diff --git a/CMakeLists.txt b/CMakeLists.txt index c835f218a..332a9b5ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,104 +1,99 @@ project(kdepimlibs) set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake/modules ) # search packages used by KDE find_package(KDE4 REQUIRED) include (KDE4Defaults) include (MacroLibrary) find_package(Boost REQUIRED) macro_log_feature(Boost_FOUND "boost" "Boost C++ Libraries" "http://www.boost.org" TRUE "1_33_0" "Needed by several critical PIM libraries.") if (NOT ONLY_KLEO) macro_optional_find_package(Sasl2) macro_log_feature(SASL2_FOUND "cyrus-sasl" "Cyrus SASL API" "http://asg.web.cmu.edu/sasl/sasl-library.html" FALSE "" "Needed to support authentication of logins. IMAP and Sieve kioslaves will not be built.") endif (NOT ONLY_KLEO) # gpgme is a hard dependency find_package(Gpgme REQUIRED) include (gpgme++/ConfigureChecks.cmake) include (ConfigureChecks.cmake) add_definitions (${QT_DEFINITIONS} ${KDE4_DEFINITIONS}) include_directories (${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${KDE4_INCLUDES}) # TODO(move to kdesupport scripts) temporary way to support gpgme-qt under win32 if (EXISTS ${CMAKE_SOURCE_DIR}/gpgme-qt) message(STATUS "gpgme-qt for Windows will be compiled: ${CMAKE_SOURCE_DIR}/gpgme-qt") add_subdirectory(gpgme-qt) endif (EXISTS ${CMAKE_SOURCE_DIR}/gpgme-qt) add_subdirectory(gpgme++) add_subdirectory(qgpgme) add_subdirectory(kmime) if (NOT ONLY_KLEO) -find_package(Akonadi REQUIRED) -if(Akonadi_FOUND) - add_subdirectory(akonadi) -endif(Akonadi_FOUND) - # (gpgme++/qgpgme handle their conditions inside their own CMakeLists.txt files) add_subdirectory(kabc) add_subdirectory(kblog) add_subdirectory(kcal) add_subdirectory(kimap) add_subdirectory(kldap) add_subdirectory(kpimidentities) add_subdirectory(kpimutils) add_subdirectory(kresources) add_subdirectory(ktnef) add_subdirectory(kxmlrpcclient) add_subdirectory(mailtransport) add_subdirectory(syndication) add_subdirectory(kioslave) endif (NOT ONLY_KLEO) add_subdirectory(cmake) # ...and append all library dependencies string(REGEX REPLACE "gpgmepp" "gpgme++" qgpgme_LIB_DEPENDS "${qgpgme_LIB_DEPENDS}") export_library_dependencies(${CMAKE_CURRENT_BINARY_DIR}/KDEPimLibsDependencies.cmake APPEND) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/KDEPimLibsDependencies.cmake DESTINATION ${DATA_INSTALL_DIR}/cmake/modules) macro_display_feature_log() # taken from kdelibs/CMakeLists.txt, needed for having different install prefixes # for kdepimlibs and kdelibs # TODO: we probably need all the other variables here as well # we need the absolute directories where stuff will be installed too # but since the variables which contain the destinations can be relative # or absolute paths, we need this macro to make them all absoulte, Alex macro(MAKE_INSTALL_PATH_ABSOLUTE out in) if (UNIX) if ("${in}" MATCHES "^/.*") set(${out} "${in}") else ("${in}" MATCHES "^/.*") set(${out} "\${KDE4_INSTALL_DIR}/${in}") endif ("${in}" MATCHES "^/.*") else (UNIX) if ("${in}" MATCHES "^[a-zA-Z]:.*") set(${out} "${in}") else ("${in}" MATCHES "^[a-zA-Z]:.*") set(${out} "\${KDE4_INSTALL_DIR}/${in}") endif ("${in}" MATCHES "^[a-zA-Z]:.*") endif (UNIX) endmacro(MAKE_INSTALL_PATH_ABSOLUTE out in) make_install_path_absolute(KDEPIMLIBS4_DBUS_INTERFACES_DIR ${DBUS_INTERFACES_INSTALL_DIR}) make_install_path_absolute(KDEPIMLIBS4_DBUS_SERVICES_DIR ${DBUS_SERVICES_INSTALL_DIR}) file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/KDEPimLibsDependencies.cmake " set(KDEPIMLIBS4_DBUS_INTERFACES_DIR \"${KDEPIMLIBS4_DBUS_INTERFACES_DIR}\") set(KDEPIMLIBS4_DBUS_SERVICES_DIR \"${KDEPIMLIBS4_DBUS_SERVICES_DIR}\") \n") diff --git a/akonadi/CMakeLists.txt b/akonadi/CMakeLists.txt deleted file mode 100644 index 77cb3138a..000000000 --- a/akonadi/CMakeLists.txt +++ /dev/null @@ -1,190 +0,0 @@ -project(akonadi-kde) - -if (KDE4_BUILD_TESTS) - # only with this macro the AKONADI_TESTS_EXPORT macro will do something - add_definitions(-DCOMPILING_TESTS) -endif (KDE4_BUILD_TESTS) - -add_subdirectory( kmime ) -add_subdirectory( tests ) - -include_directories( - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_BINARY_DIR} - ${QT_QTDBUS_INCLUDE_DIR} - ${Boost_INCLUDE_DIR} - ${KDE4_INCLUDE_DIR} - ${AKONADI_INCLUDE_DIR} - ${AKONADI_INCLUDE_DIR}/akonadi/private -) - -# libakonadi-kde - -set( akonadikde_LIB_SRC - entity.cpp # keep it at top to not break enable-final - agentbase.cpp - agentfilterproxymodel.cpp - agentinstance.cpp - agentinstancecreatejob.cpp - agentinstancemodel.cpp - agentinstancewidget.cpp - agentmanager.cpp - agenttype.cpp - agenttypemodel.cpp - agenttypewidget.cpp - attribute.cpp - attributefactory.cpp - cachepolicy.cpp - cachepolicypage.cpp - changerecorder.cpp - collection.cpp - collectioncopyjob.cpp - collectioncreatejob.cpp - collectiondeletejob.cpp - collectiondisplayattribute.cpp - collectionfilterproxymodel.cpp - collectiongeneralpropertiespage.cpp - collectionfetchjob.cpp - collectionmodel.cpp - collectionmodel_p.cpp - collectionmodifyjob.cpp - collectionpathresolver.cpp - collectionpropertiesdialog.cpp - collectionpropertiespage.cpp - collectionrightsattribute.cpp - collectionselectjob.cpp - collectionstatistics.cpp - collectionstatisticsdelegate.cpp - collectionstatisticsjob.cpp - collectionstatisticsmodel.cpp - collectionsync.cpp - collectionview.cpp - control.cpp - expungejob.cpp - flatcollectionproxymodel.cpp - item.cpp - itemcreatejob.cpp - itemcopyjob.cpp - itemdeletejob.cpp - itemfetchjob.cpp - itemfetchscope.cpp - itemmodel.cpp - itemmonitor.cpp - itemmovejob.cpp - itemserializer.cpp - itemserializerplugin.cpp - itemmodifyjob.cpp - itemsync.cpp - itemview.cpp - job.cpp - monitor.cpp - monitor_p.cpp - pastehelper.cpp - protocolhelper.cpp - resourcebase.cpp - resourcescheduler.cpp - searchcreatejob.cpp - session.cpp - standardactionmanager.cpp - subscriptionjob.cpp - subscriptionchangeproxymodel.cpp - subscriptiondialog.cpp - subscriptionmodel.cpp - transactionjobs.cpp - transactionsequence.cpp -# Temporary until ported to Qt-plugin framework - pluginloader.cpp -) - -# DBus interfaces and adaptors -set(akonadi_xml ${AKONADI_DBUS_INTERFACES_DIR}/org.freedesktop.Akonadi.NotificationManager.xml) -set_source_files_properties(${akonadi_xml} PROPERTIES INCLUDE "notificationmessage_p.h") -qt4_add_dbus_interface( akonadikde_LIB_SRC ${akonadi_xml} notificationmanagerinterface ) -qt4_add_dbus_interfaces( akonadikde_LIB_SRC ${AKONADI_DBUS_INTERFACES_DIR}/org.freedesktop.Akonadi.AgentManager.xml ) -qt4_add_dbus_interfaces( akonadikde_LIB_SRC ${AKONADI_DBUS_INTERFACES_DIR}/org.freedesktop.Akonadi.Tracer.xml ) -qt4_add_dbus_adaptor( akonadikde_LIB_SRC ${AKONADI_DBUS_INTERFACES_DIR}/org.freedesktop.Akonadi.Resource.xml resourcebase.h Akonadi::ResourceBase ) -qt4_add_dbus_adaptor( akonadikde_LIB_SRC ${AKONADI_DBUS_INTERFACES_DIR}/org.freedesktop.Akonadi.Agent.Status.xml agentbase.h Akonadi::AgentBase ) -qt4_add_dbus_adaptor( akonadikde_LIB_SRC org.freedesktop.Akonadi.Agent.Control.xml agentbase.h Akonadi::AgentBase ) - -kde4_add_ui_files( akonadikde_LIB_SRC - cachepolicypage.ui - collectiongeneralpropertiespage.ui - subscriptiondialog.ui -) - -kde4_add_library( akonadi-kde SHARED ${akonadikde_LIB_SRC} ) - -target_link_libraries( akonadi-kde ${QT_QTNETWORK_LIBRARY} ${QT_QTDBUS_LIBRARY} ${KDE4_KDEUI_LIBS} ${KDE4_KDE3SUPPORT_LIBS} ${AKONADI_COMMON_LIBRARIES} ) -set_target_properties( akonadi-kde PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION} ) -install( TARGETS akonadi-kde ${INSTALL_TARGETS_DEFAULT_ARGS} ) - -########### install files ############### - -install( FILES - akonadi_export.h - agentbase.h - agentfilterproxymodel.h - agentinstance.h - agentinstancecreatejob.h - agentinstancemodel.h - agentinstancewidget.h - agentmanager.h - agenttype.h - agenttypemodel.h - agenttypewidget.h - attribute.h - attributefactory.h - cachepolicy.h - changerecorder.h - collection.h - collectioncopyjob.h - collectioncreatejob.h - collectiondeletejob.h - collectiondisplayattribute.h - collectionfilterproxymodel.h - collectionfetchjob.h - collectionmodel.h - collectionmodifyjob.h - collectionpropertiesdialog.h - collectionpropertiespage.h - collectionstatisticsdelegate.h - collectionstatisticsmodel.h - collectionstatistics.h - collectionstatisticsjob.h - collectionview.h - control.h - entity.h - item.h - itemcreatejob.h - itemcopyjob.h - itemdeletejob.h - itemfetchjob.h - itemfetchscope.h - itemmodel.h - itemmodifyjob.h - itemmonitor.h - itemmovejob.h - itempayloadinternals_p.h - itemserializerplugin.h - itemsync.h - itemview.h - job.h - monitor.h - resourcebase.h - searchcreatejob.h - session.h - standardactionmanager.h - transactionjobs.h - transactionsequence.h - DESTINATION ${INCLUDE_INSTALL_DIR}/akonadi COMPONENT Devel -) - -install( FILES - collectionpathresolver_p.h - DESTINATION ${INCLUDE_INSTALL_DIR}/akonadi/private COMPONENT Devel - ) - -install( FILES - kcfg2dbus.xsl - DESTINATION ${DATA_INSTALL_DIR}/akonadi-kde -) diff --git a/akonadi/Mainpage.dox b/akonadi/Mainpage.dox deleted file mode 100644 index f9cc1b59d..000000000 --- a/akonadi/Mainpage.dox +++ /dev/null @@ -1,92 +0,0 @@ -/** @mainpage Akonadi client library - -\section libakonadi_intro Introduction - -libakonadi is the client access library for using the Akonadi PIM data server. -All processes accessing Akonadi, including those which communicate with a remote -server (\ref akonadi_design_agents "agents"), are considered clients. - -Functionality provided by libakonadi: - -- \ref libakonadi_jobs -- \ref libakonadi_monitor -- \ref libakonadi_collections -- \ref libakonadi_pimitems -- \ref libakonadi_serializer -- \ref libakonadi_resource - -\section libakonadi_jobs Accessing the Akonadi server - -Accessing the Akonadi server is done using job-classes derived from Akonadi::Job. The -communication channel with the server is provided by Akonadi::Session. - -\todo Complete this section. - -\section libakonadi_monitor Change notifications - -The Akonadi::Monitor class allows you to monitor specific resources, -\ref akonadi_concepts_collections "collections" and PIM items for changes. - -\section libakonadi_collections Collection retrieval and manipulation - -See \ref akonadi_concepts_collections "Collection Concept" for more information -about the concept of collections. A collection is represented by the Akonadi::Collection class. - -Classes to retrieve information about collections: - -- Akonadi::CollectionFetchJob -- Akonadi::CollectionSelectJob -- Akonadi::CollectionStatisticsJob - -Classes to manipulate collections: - -- Akonadi::CollectionCreateJob -- Akonadi::CollectionModifyJob -- Akonadi::CollectionDeleteJob - -There is also Akonadi::CollectionModel, which is a self-updating model class which can -be used in combination with Akonadi::CollectionView. Akonadi::CollectionFilterProxyModel -can be used to limit a displayed collection tree to collections supporting a certain -type of PIM items. - -\section libakonadi_pimitems PIM item retrieval and manipulation - -PIM items are represented by classes derived from Akonadi::Item. -Items can be retrieved using job classes derived from Akonadi::ItemFetchJob. - -The following classes are provided to manipulate PIM items: - -- Akonadi::ItemCreateJob -- Akonadi::ItemModifyJob -- Akonadi::ItemDeleteJob -- Akonadi::ExpungeJob - -Akonadi::ItemModel provides a self-updating model class which can be used to display the content -of a collection. - -\section libakonadi_serializer PIM item serializer - -The class Akonadi::ItemSerializer is responsible for converting between the stored (binary) representation -of a PIM item and the objects used to handle these items provided by the corresponding libraries (kabc, kcal, etc.). - -Serializer plugins allow you to add support for new kinds of PIM items to Akonadi. -Akonadi::ItemSerializerPlugin can be used as a base class for such a plugin. - -\section libakonadi_resource Agents and Resources - -The class Akonadi::AgentBase is the commen base class for all agents. It provides commonly needed -functionality such as change monitoring and recording. - -Resources are special type of agents, Akonadi::ResourceBase is the base class them. It provides the -necessary interfaces to the server as well as many convenience functions to make implementing -a new resource as easy as possible. - -*/ - -/** - -\defgroup AkonadiMacros Akonadi Macros - -*/ - -// DOXYGEN_REFERENCES = kdecore kdeui diff --git a/akonadi/Messages.sh b/akonadi/Messages.sh deleted file mode 100755 index 7d40bad4b..000000000 --- a/akonadi/Messages.sh +++ /dev/null @@ -1,2 +0,0 @@ -#! /bin/sh -$XGETTEXT *.cpp *.h -o $podir/libakonadi.pot diff --git a/akonadi/README b/akonadi/README deleted file mode 100644 index f959f1dd1..000000000 --- a/akonadi/README +++ /dev/null @@ -1,3 +0,0 @@ -See Mainpage.dox for more information. - -See libakonadi.xmi for UML documentation generated with Umbrello. diff --git a/akonadi/agentbase.cpp b/akonadi/agentbase.cpp deleted file mode 100644 index 8320c29a3..000000000 --- a/akonadi/agentbase.cpp +++ /dev/null @@ -1,480 +0,0 @@ -/* - Copyright (c) 2006 Till Adam - Copyright (c) 2007 Volker Krause - Copyright (c) 2007 Bruno Virlet - Copyright (c) 2008 Kevin Krammer - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "agentbase.h" -#include "agentbase_p.h" - -#include "controladaptor.h" -#include "statusadaptor.h" -#include "monitor_p.h" -#include "xdgbasedirs_p.h" - -#include "session.h" -#include "session_p.h" -#include "changerecorder.h" -#include "itemfetchjob.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include - -using namespace Akonadi; - -static AgentBase *sAgentBase = 0; - -AgentBase::Observer::Observer() -{ -} - -AgentBase::Observer::~Observer() -{ -} - -void AgentBase::Observer::itemAdded( const Item &item, const Collection &collection ) -{ - kDebug() << "sAgentBase=" << (void*) sAgentBase << "this=" << (void*) this; - Q_UNUSED( item ); - Q_UNUSED( collection ); - if ( sAgentBase != 0 ) - sAgentBase->d_ptr->changeProcessed(); -} - -void AgentBase::Observer::itemChanged( const Item &item, const QSet &partIdentifiers ) -{ - kDebug() << "sAgentBase=" << (void*) sAgentBase << "this=" << (void*) this; - Q_UNUSED( item ); - Q_UNUSED( partIdentifiers ); - if ( sAgentBase != 0 ) - sAgentBase->d_ptr->changeProcessed(); -} - -void AgentBase::Observer::itemRemoved( const Item &item ) -{ - kDebug() << "sAgentBase=" << (void*) sAgentBase << "this=" << (void*) this; - Q_UNUSED( item ); - if ( sAgentBase != 0 ) - sAgentBase->d_ptr->changeProcessed(); -} - -void AgentBase::Observer::collectionAdded( const Akonadi::Collection &collection, const Akonadi::Collection &parent ) -{ - kDebug() << "sAgentBase=" << (void*) sAgentBase << "this=" << (void*) this; - Q_UNUSED( collection ); - Q_UNUSED( parent ); - if ( sAgentBase != 0 ) - sAgentBase->d_ptr->changeProcessed(); -} - -void AgentBase::Observer::collectionChanged( const Collection &collection ) -{ - kDebug() << "sAgentBase=" << (void*) sAgentBase << "this=" << (void*) this; - Q_UNUSED( collection ); - if ( sAgentBase != 0 ) - sAgentBase->d_ptr->changeProcessed(); -} - -void AgentBase::Observer::collectionRemoved( const Collection &collection ) -{ - kDebug() << "sAgentBase=" << (void*) sAgentBase << "this=" << (void*) this; - Q_UNUSED( collection ); - if ( sAgentBase != 0 ) - sAgentBase->d_ptr->changeProcessed(); -} - -//@cond PRIVATE - -AgentBasePrivate::AgentBasePrivate( AgentBase *parent ) - : q_ptr( parent ), - mStatusCode( AgentBase::Idle ), - mProgress( 0 ), - mOnline( false ), - mSettings( 0 ), - mObserver( 0 ) -{ -} - -AgentBasePrivate::~AgentBasePrivate() -{ - mMonitor->setConfig( 0 ); - delete mSettings; -} - -void AgentBasePrivate::init() -{ - Q_Q( AgentBase ); - - /** - * Create a default session for this process. - */ - SessionPrivate::createDefaultSession( mId.toLatin1() ); - - mTracer = new org::freedesktop::Akonadi::Tracer( QLatin1String( "org.freedesktop.Akonadi" ), QLatin1String( "/tracing" ), - QDBusConnection::sessionBus(), q ); - - new ControlAdaptor( q ); - new StatusAdaptor( q ); - if ( !QDBusConnection::sessionBus().registerObject( QLatin1String( "/" ), q, QDBusConnection::ExportAdaptors ) ) - q->error( QString::fromLatin1( "Unable to register object at dbus: %1" ).arg( QDBusConnection::sessionBus().lastError().message() ) ); - - mSettings = new QSettings( QString::fromLatin1( "%1/agent_config_%2" ).arg( XdgBaseDirs::saveDir( "config", QLatin1String( "akonadi" ) ), mId ), QSettings::IniFormat ); - - mMonitor = new ChangeRecorder( q ); - mMonitor->ignoreSession( Session::defaultSession() ); - mMonitor->itemFetchScope().setCacheOnly( true ); - mMonitor->setConfig( mSettings ); - - mOnline = mSettings->value( QLatin1String( "Agent/Online" ), true ).toBool(); - - connect( mMonitor, SIGNAL( itemAdded( const Akonadi::Item&, const Akonadi::Collection& ) ), - SLOT( itemAdded( const Akonadi::Item&, const Akonadi::Collection& ) ) ); - connect( mMonitor, SIGNAL( itemChanged( const Akonadi::Item&, const QSet& ) ), - SLOT( itemChanged( const Akonadi::Item&, const QSet& ) ) ); - connect( mMonitor, SIGNAL( itemRemoved( const Akonadi::Item& ) ), - SLOT( itemRemoved( const Akonadi::Item& ) ) ); - connect( mMonitor, SIGNAL(collectionAdded(Akonadi::Collection,Akonadi::Collection)), - SLOT(collectionAdded(Akonadi::Collection,Akonadi::Collection)) ); - connect( mMonitor, SIGNAL( collectionChanged( const Akonadi::Collection& ) ), - SLOT( collectionChanged( const Akonadi::Collection& ) ) ); - connect( mMonitor, SIGNAL( collectionRemoved( const Akonadi::Collection& ) ), - SLOT( collectionRemoved( const Akonadi::Collection& ) ) ); - - connect( q, SIGNAL( status( int, QString ) ), q, SLOT( slotStatus( int, QString ) ) ); - connect( q, SIGNAL( percent( int ) ), q, SLOT( slotPercent( int ) ) ); - connect( q, SIGNAL( warning( QString ) ), q, SLOT( slotWarning( QString ) ) ); - connect( q, SIGNAL( error( QString ) ), q, SLOT( slotError( QString ) ) ); - - QTimer::singleShot( 0, q, SLOT( delayedInit() ) ); -} - -void AgentBasePrivate::delayedInit() -{ - Q_Q( AgentBase ); - if ( !QDBusConnection::sessionBus().registerService( QLatin1String( "org.freedesktop.Akonadi.Agent." ) + mId ) ) - kFatal() << "Unable to register service at dbus:" << QDBusConnection::sessionBus().lastError().message(); - q->setOnline( mOnline ); -} - -void AgentBasePrivate::itemAdded( const Akonadi::Item &item, const Akonadi::Collection &collection ) -{ - kDebug() << "mObserver=" << (void*) mObserver << "this=" << (void*) this; - if ( mObserver != 0 ) - mObserver->itemAdded( item, collection ); -} - -void AgentBasePrivate::itemChanged( const Akonadi::Item &item, const QSet &partIdentifiers ) -{ - kDebug() << "mObserver=" << (void*) mObserver << "this=" << (void*) this; - if ( mObserver != 0 ) - mObserver->itemChanged( item, partIdentifiers ); -} - -void AgentBasePrivate::itemRemoved( const Akonadi::Item &item ) -{ - kDebug() << "mObserver=" << (void*) mObserver << "this=" << (void*) this; - if ( mObserver != 0 ) - mObserver->itemRemoved( item ); -} - -void AgentBasePrivate::collectionAdded( const Akonadi::Collection &collection, const Akonadi::Collection &parent ) -{ - kDebug() << "mObserver=" << (void*) mObserver << "this=" << (void*) this; - if ( mObserver != 0 ) - mObserver->collectionAdded( collection, parent ); -} - -void AgentBasePrivate::collectionChanged( const Akonadi::Collection &collection ) -{ - kDebug() << "mObserver=" << (void*) mObserver << "this=" << (void*) this; - if ( mObserver != 0 ) - mObserver->collectionChanged( collection ); -} - -void AgentBasePrivate::collectionRemoved( const Akonadi::Collection &collection ) -{ - kDebug() << "mObserver=" << (void*) mObserver << "this=" << (void*) this; - if ( mObserver != 0 ) - mObserver->collectionRemoved( collection ); -} - -void AgentBasePrivate::changeProcessed() -{ - mMonitor->changeProcessed(); - QTimer::singleShot( 0, mMonitor, SLOT( replayNext() ) ); -} - -void AgentBasePrivate::slotStatus( int status, const QString &message ) -{ - mStatusMessage = message; - mStatusCode = 0; - - switch ( status ) { - case AgentBase::Idle: - if ( mStatusMessage.isEmpty() ) - mStatusMessage = defaultReadyMessage(); - - mStatusCode = 0; - break; - case AgentBase::Running: - if ( mStatusMessage.isEmpty() ) - mStatusMessage = defaultSyncingMessage(); - - mStatusCode = 1; - break; - case AgentBase::Broken: - if ( mStatusMessage.isEmpty() ) - mStatusMessage = defaultErrorMessage(); - - mStatusCode = 2; - break; - default: - Q_ASSERT( !"Unknown status passed" ); - break; - } -} - -void AgentBasePrivate::slotPercent( int progress ) -{ - mProgress = progress; -} - -void AgentBasePrivate::slotWarning( const QString& message ) -{ - mTracer->warning( QString::fromLatin1( "AgentBase(%1)" ).arg( mId ), message ); -} - -void AgentBasePrivate::slotError( const QString& message ) -{ - mTracer->error( QString::fromLatin1( "AgentBase(%1)" ).arg( mId ), message ); -} - - -AgentBase::AgentBase( const QString & id ) - : d_ptr( new AgentBasePrivate( this ) ) -{ - sAgentBase = this; - d_ptr->mId = id; - d_ptr->init(); -} - -// @endcond - -AgentBase::AgentBase( AgentBasePrivate* d, const QString &id ) : - d_ptr( d ) -{ - sAgentBase = this; - d_ptr->mId = id; - d_ptr->init(); -} - -AgentBase::~AgentBase() -{ - delete d_ptr; -} - -static char* sAgentAppName = 0; - -QString AgentBase::parseArguments( int argc, char **argv ) -{ - QString identifier; - if ( argc < 3 ) { - kDebug( 5250 ) << "Not enough arguments passed..."; - exit( 1 ); - } - - for ( int i = 1; i < argc - 1; ++i ) { - if ( QLatin1String( argv[ i ] ) == QLatin1String( "--identifier" ) ) - identifier = QLatin1String( argv[ i + 1 ] ); - } - - if ( identifier.isEmpty() ) { - kDebug( 5250 ) << "Identifier argument missing"; - exit( 1 ); - } - - sAgentAppName = qstrdup( identifier.toLatin1().constData() ); - KCmdLineArgs::init( argc, argv, sAgentAppName, 0, ki18n("Akonadi Agent"),"0.1" , - ki18n("Akonadi Agent") ); - - KCmdLineOptions options; - options.add("identifier ", ki18n("Agent identifier")); - KCmdLineArgs::addCmdLineOptions( options ); - - return identifier; -} - -int AgentBase::init( AgentBase *r ) -{ - QApplication::setQuitOnLastWindowClosed( false ); - int rv = kapp->exec(); - delete r; - delete[] sAgentAppName; - return rv; -} - -int AgentBase::status() const -{ - Q_D( const AgentBase ); - - return d->mStatusCode; -} - -QString AgentBase::statusMessage() const -{ - Q_D( const AgentBase ); - - return d->mStatusMessage; -} - -int AgentBase::progress() const -{ - Q_D( const AgentBase ); - - return d->mProgress; -} - -QString AgentBase::progressMessage() const -{ - Q_D( const AgentBase ); - - return d->mProgressMessage; -} - -bool AgentBase::isOnline() const -{ - Q_D( const AgentBase ); - - return d->mOnline; -} - -void AgentBase::setOnline( bool state ) -{ - Q_D( AgentBase ); - d->mOnline = state; - d->mSettings->setValue( QLatin1String( "Agent/Online" ), state ); - doSetOnline( state ); -} - -void AgentBase::doSetOnline( bool online ) -{ - Q_UNUSED( online ); -} - -void AgentBase::configure( WId windowId ) -{ - Q_UNUSED( windowId ); -} - -#ifdef Q_OS_WIN -void AgentBase::configure( qlonglong windowId ) -{ - configure( reinterpret_cast( windowId ) ); -} -#endif - -WId AgentBase::winIdForDialogs() const -{ - bool registered = QDBusConnection::sessionBus().interface()->isServiceRegistered( QLatin1String("org.freedesktop.akonaditray") ); - if ( !registered ) - return 0; - - QDBusInterface dbus( QLatin1String("org.freedesktop.akonaditray"), QLatin1String("/Actions"), - QLatin1String("org.freedesktop.Akonadi.Tray") ); - QDBusMessage reply = dbus.call( QLatin1String("getWinId") ); - - if ( reply.type() == QDBusMessage::ErrorMessage ) - return 0; - - WId winid = (WId)reply.arguments().at( 0 ).toLongLong(); - return winid; -} - -void AgentBase::quit() -{ - Q_D( AgentBase ); - aboutToQuit(); - - if ( d->mSettings ) { - d->mMonitor->setConfig( 0 ); - d->mSettings->sync(); - } - - QCoreApplication::exit( 0 ); -} - -void AgentBase::aboutToQuit() -{ -} - -void AgentBase::cleanup() -{ - Q_D( AgentBase ); - const QString fileName = d->mSettings->fileName(); - - /* - * First destroy the settings object... - */ - d->mMonitor->setConfig( 0 ); - delete d->mSettings; - d->mSettings = 0; - - /* - * ... then remove the file from hd. - */ - QFile::remove( fileName ); - - QCoreApplication::quit(); -} - -void AgentBase::registerObserver( Observer *observer ) -{ - kDebug() << "observer=" << (void*) observer << "this=" << (void*) this; - d_ptr->mObserver = observer; -} - -QString AgentBase::identifier() const -{ - return d_ptr->mId; -} - -void AgentBase::changeProcessed() -{ - Q_D( AgentBase ); - d->changeProcessed(); -} - -ChangeRecorder * AgentBase::changeRecorder() const -{ - return d_ptr->mMonitor; -} - -#include "agentbase.moc" -#include "agentbase_p.moc" diff --git a/akonadi/agentbase.h b/akonadi/agentbase.h deleted file mode 100644 index 1943449b5..000000000 --- a/akonadi/agentbase.h +++ /dev/null @@ -1,446 +0,0 @@ -/* - This file is part of akonadiresources. - - Copyright (c) 2006 Till Adam - Copyright (c) 2007 Volker Krause - Copyright (c) 2008 Kevin Krammer - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_AGENTBASE_H -#define AKONADI_AGENTBASE_H - -#include "akonadi_export.h" - -#include - -#include - -class ControlAdaptor; -class StatusAdaptor; - -namespace Akonadi { - -class AgentBasePrivate; -class ChangeRecorder; -class Collection; -class Item; -class Session; - -/** - * @short The base class for all Akonadi agents and resources. - * - * This class is a base class for all Akonadi agents, which covers the real - * agent processes and all resources. - * - * It provides: - * - lifetime management - * - change monitoring and recording - * - configuration interface - * - problem reporting - * - * @author Till Adam , Volker Krause - */ -class AKONADI_EXPORT AgentBase : public QObject, protected QDBusContext -{ - Q_OBJECT - - public: - /** - * @short The interface for reacting on monitored or replayed changes. - * - * The Observer provides an interface to react on monitored or replayed changes. - * - * Since the this base class does only tell the change recorder that the change - * has been processed, an AgentBase subclass which wants to actually process - * the change needs to subclass Observer and reimplement the methods it is - * interested in. - * - * Such an agent specific Observer implementation can either be done - * stand-alone, i.e. as a separate object, or by inheriting both AgentBase - * and AgentBase::Observer. - * - * The observer implementation then has registered with the agent, so it - * can forward the incoming changes to the observer. - * - * @note In the multiple inheritance approach the init() method automatically - * registers itself as the observer. - * - * Example for stand-alone observer: - * @code - * class ExampleAgent : public AgentBase - * { - * public: - * ExampleAgent( const QString &id ); - * - * ~ExampleAgent(); - * - * private: - * AgentBase::Observer *mObserver; - * }; - * - * class ExampleObserver : public AgentBase::Observer - * { - * protected: - * void itemChanged( const Item &item ); - * }; - * - * ExampleAgent::ExampleAgent( const QString &id ) - * : AgentBase( id ), mObserver( 0 ) - * { - * mObserver = new ExampleObserver(); - * registerObserver( mObserver ); - * } - * - * ExampleAgent::~ExampleAgent() - * { - * delete mObserver; - * } - * - * void ExampleObserver::itemChanged( const Item &item ) - * { - * // do something with item - * kDebug() << "Item id=" << item.id(); - * - * // let base implementation tell the change recorder that we - * // have processed the change - * AgentBase::Observer::itemChanged( item ); - * } - * @endcode - * - * Example for observer through multiple inheritance: - * @code - * class ExampleAgent : public AgentBase, public AgentBase::Observer - * { - * public: - * ExampleAgent( const QString &id ); - * - * protected: - * void itemChanged( const Item &item ); - * }; - * - * ExampleAgent::ExampleAgent( const QString &id ) - * : AgentBase( id ) - * { - * // no need to create or register observer since - * // we are the observer and registration happens automatically - * // in init() - * } - * - * void ExampleAgent::itemChanged( const Item &item ) - * { - * // do something with item - * kDebug() << "Item id=" << item.id(); - * - * // let base implementation tell the change recorder that we - * // have processed the change - * AgentBase::Observer::itemChanged( item ); - * } - * @endcode - * - * @author Kevin Krammer - */ - class AKONADI_EXPORT Observer // krazy:exclude=dpointer - { - public: - /** - * Creates an observer instance. - */ - Observer(); - - /** - * Destroys the observer instance. - */ - virtual ~Observer(); - - /** - * Reimplement to handle adding of new items. - * @param item The newly added item. - * @param collection The collection @p item got added to. - */ - virtual void itemAdded( const Akonadi::Item &item, const Akonadi::Collection &collection ); - - /** - * Reimplement to handle changes to existing items. - * @param item The changed item. - * @param partIdentifiers The identifiers of the item parts that has been changed. - */ - virtual void itemChanged( const Akonadi::Item &item, const QSet &partIdentifiers ); - - /** - * Reimplement to handle deletion of items. - * @param item The deleted item. - */ - virtual void itemRemoved( const Akonadi::Item &item ); - - /** - * Reimplement to handle adding of new collections. - * @param collection The newly added collection. - * @param parent The parent collection. - */ - virtual void collectionAdded( const Akonadi::Collection &collection, const Akonadi::Collection &parent ); - - /** - * Reimplement to handle changes to existing collections. - * @param collection The changed collection. - */ - virtual void collectionChanged( const Akonadi::Collection &collection ); - - /** - * Reimplement to handle deletion of collections. - * @param collection The deleted collection. - */ - virtual void collectionRemoved( const Akonadi::Collection &collection ); - }; - - /** - * This enum describes the different states the - * agent can be in. - */ - enum Status - { - Idle = 0, ///< The agent does currently nothing. - Running, ///< The agent is working on something. - Broken ///< The agent encountered an error state. - }; - - /** - * Use this method in the main function of your agent - * application to initialize your agent subclass. - * This method also takes care of creating a KApplication - * object and parsing command line arguments. - * - * @note In case the given class is also derived from AgentBase::Observer - * it gets registered as its own observer (see AgentBase::Observer), e.g. - * agentInstance->registerObserver( agentInstance ); - * - * @code - * - * class MyAgent : public AgentBase - * { - * ... - * }; - * - * AKONADI_AGENT_MAIN( MyAgent ) - * - * @endcode - */ - template - static int init( int argc, char **argv ) - { - const QString id = parseArguments( argc, argv ); - KApplication app; - T* r = new T( id ); - - // check if T also inherits AgentBase::Observer and - // if it does, automatically register it on itself - Observer *observer = dynamic_cast( r ); - if ( observer != 0 ) - r->registerObserver( observer ); - return init( r ); - } - - /** - * This method returns the current status code of the agent. - * - * The following return values are possible: - * - * - 0 - Idle - * - 1 - Running - * - 2 - Broken - */ - virtual int status() const; - - /** - * This method returns an i18n'ed description of the current status code. - */ - virtual QString statusMessage() const; - - /** - * This method returns the current progress of the agent in percentage. - */ - virtual int progress() const; - - /** - * This method returns an i18n'ed description of the current progress. - */ - virtual QString progressMessage() const; - - /** - * This method is called whenever the agent shall show its configuration dialog - * to the user. It will be automatically called when the agent is started for - * the first time. - * @param windowId The parent window id. - */ - virtual void configure( WId windowId ); - - /** - * This method returns the windows id, which should be used for dialogs. - */ - WId winIdForDialogs() const; - -#ifdef Q_OS_WIN - /** - * Overload of @ref configure needed because WId cannot be automatically casted - * to qlonglong on Windows. - */ - void configure( qlonglong windowId ); -#endif - - /** - * Returns the instance identifier of this agent. - */ - QString identifier() const; - - /** - * This method is called when the agent is removed from - * the system, so it can do some cleanup stuff. - */ - virtual void cleanup(); - - /** - * Registers the given observer for reacting on monitored or recorded changes. - * - * @param observer The change handler to register. No ownership transfer, i.e. - * the caller stays owner of the pointer and can reset - * the registration by calling this method with @c 0 - */ - void registerObserver( Observer *observer ); - - Q_SIGNALS: - /** - * This signal should be emitted whenever the status of the agent has been changed. - * @param status The new Status code. - * @param message A i18n'ed description of the new status. - */ - void status( int status, const QString &message = QString() ); - - /** - * This signal should be emitted whenever the progress of an action in the agent - * (e.g. data transfer, connection establishment to remote server etc.) has changed. - * - * @param progress The progress of the action in percent. - */ - void percent( int progress ); - - /** - * This signal shall be used to report warnings. - * - * @param message The i18n'ed warning message. - */ - void warning( const QString& message ); - - /** - * This signal shall be used to report errors. - * - * @param message The i18n'ed error message. - */ - void error( const QString& message ); - - protected: - /** - * Creates an agent base. - * - * @param id The instance id of the agent. - */ - AgentBase( const QString & id ); - - /** - * Destroys the agent base. - */ - ~AgentBase(); - - /** - * This method is called whenever the agent application is about to - * quit. - * - * Reimplement this method to do session cleanup (e.g. disconnecting - * from groupware server). - */ - virtual void aboutToQuit(); - - /** - * Returns the Akonadi::ChangeRecorder object used for monitoring. - * Use this to configure which parts you want to monitor. - */ - ChangeRecorder* changeRecorder() const; - - /** - * Marks the current change as processes and replays the next change if change - * recording is enabled (noop otherwise). This method is called - * from the default implementation of the change notification slots. While not - * required when not using change recording, it is nevertheless recommended - * to call this method when done with processing a change notification. - */ - void changeProcessed(); - - /** - * Returns whether the agent is currently online. - */ - bool isOnline() const; - - /** - * Sets whether the agent shall be online or not. - */ - void setOnline( bool state ); - - protected: - //@cond PRIVATE - AgentBasePrivate *d_ptr; - explicit AgentBase( AgentBasePrivate* d, const QString &id ); - //@endcond - - /** - * This method is called whenever the @p online status has changed. - * Reimplement this method to react on online status changes. - */ - virtual void doSetOnline( bool online ); - - private: - //@cond PRIVATE - static QString parseArguments( int, char** ); - static int init( AgentBase *r ); - - void quit(); - - // dbus agent interface - friend class ::StatusAdaptor; - friend class ::ControlAdaptor; - - Q_DECLARE_PRIVATE( AgentBase ) - Q_PRIVATE_SLOT( d_func(), void delayedInit() ) - Q_PRIVATE_SLOT( d_func(), void slotStatus( int, const QString& ) ) - Q_PRIVATE_SLOT( d_func(), void slotPercent( int ) ) - Q_PRIVATE_SLOT( d_func(), void slotWarning( const QString& ) ) - Q_PRIVATE_SLOT( d_func(), void slotError( const QString& ) ) - //@endcond -}; - -} - -#ifndef AKONADI_AGENT_MAIN -/** - * Convenience Macro for the most common main() function for Akonadi agents. - */ -#define AKONADI_AGENT_MAIN( agentClass ) \ - int main( int argc, char **argv ) \ - { \ - return Akonadi::AgentBase::init( argc, argv ); \ - } -#endif - -#endif diff --git a/akonadi/agentbase_p.h b/akonadi/agentbase_p.h deleted file mode 100644 index 406f4a48e..000000000 --- a/akonadi/agentbase_p.h +++ /dev/null @@ -1,106 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - Copyright (c) 2008 Kevin Krammer - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_AGENTBASE_P_H -#define AKONADI_AGENTBASE_P_H - -#include "agentbase.h" -#include "tracerinterface.h" - -#include - -class QSettings; - -namespace Akonadi { - -/** - * @internal - */ -class AgentBasePrivate : public QObject -{ - Q_OBJECT - public: - AgentBasePrivate( AgentBase *parent ); - virtual ~AgentBasePrivate(); - void init(); - virtual void delayedInit(); - - void slotStatus( int status, const QString &message ); - void slotPercent( int progress ); - void slotWarning( const QString& message ); - void slotError( const QString& message ); - - virtual void changeProcessed(); - - QString defaultReadyMessage() const - { - if ( mOnline ) - return i18nc( "@info:status, application ready for work", "Ready" ); - return i18nc( "@info:status", "Offline" ); - } - - QString defaultSyncingMessage() const - { - return i18nc( "@info:status", "Syncing..." ); - } - - QString defaultErrorMessage() const - { - return i18nc( "@info:status", "Error!" ); - } - - AgentBase *q_ptr; - Q_DECLARE_PUBLIC( AgentBase ) - - QString mId; - - int mStatusCode; - QString mStatusMessage; - - uint mProgress; - QString mProgressMessage; - - bool mOnline; - - QSettings *mSettings; - - ChangeRecorder *mMonitor; - - org::freedesktop::Akonadi::Tracer *mTracer; - - AgentBase::Observer *mObserver; - - protected Q_SLOTS: - virtual void itemAdded( const Akonadi::Item &item, const Akonadi::Collection &collection ); - - virtual void itemChanged( const Akonadi::Item &item, const QSet &partIdentifiers ); - - virtual void itemRemoved( const Akonadi::Item &item ); - - virtual void collectionAdded( const Akonadi::Collection &collection, const Akonadi::Collection &parent ); - - virtual void collectionChanged( const Akonadi::Collection &collection ); - - virtual void collectionRemoved( const Akonadi::Collection &collection ); -}; - -} - -#endif diff --git a/akonadi/agentfilterproxymodel.cpp b/akonadi/agentfilterproxymodel.cpp deleted file mode 100644 index 24bcf1730..000000000 --- a/akonadi/agentfilterproxymodel.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "agentfilterproxymodel.h" - -#include "agenttypemodel.h" -#include "agentinstancemodel.h" - -#include -#include - -#include - -#include - -using namespace Akonadi; - -// ensure the role numbers are equivalent for both source models -BOOST_STATIC_ASSERT( (int)AgentTypeModel::CapabilitiesRole == (int)AgentInstanceModel::CapabilitiesRole ); -BOOST_STATIC_ASSERT( (int)AgentTypeModel::MimeTypesRole == (int)AgentInstanceModel::MimeTypesRole ); - -/** - * @internal - */ -class AgentFilterProxyModel::Private -{ - public: - QStringList mimeTypes; - QStringList capabilities; -}; - -AgentFilterProxyModel::AgentFilterProxyModel(QObject * parent) - : QSortFilterProxyModel( parent ), - d( new Private ) -{ - setDynamicSortFilter( true ); -} - -AgentFilterProxyModel::~AgentFilterProxyModel() -{ - delete d; -} - -void AgentFilterProxyModel::addMimeTypeFilter(const QString & mimeType) -{ - d->mimeTypes << mimeType; - invalidateFilter(); -} - -void AgentFilterProxyModel::addCapabilityFilter(const QString & capability) -{ - d->capabilities << capability; - invalidateFilter(); -} - -void AgentFilterProxyModel::clearFilters() -{ - d->capabilities.clear(); - d->mimeTypes.clear(); - invalidateFilter(); -} - -bool AgentFilterProxyModel::filterAcceptsRow(int row, const QModelIndex&) const -{ - QModelIndex index = sourceModel()->index( row, 0 ); - if ( !d->mimeTypes.isEmpty() ) { - bool found = false; - foreach ( const QString &mt, index.data( AgentTypeModel::MimeTypesRole ).toStringList() ) { - if ( d->mimeTypes.contains( mt ) ) { - found = true; - } else { - KMimeType::Ptr mimeType = KMimeType::mimeType( mt, KMimeType::ResolveAliases ); - if ( !mimeType.isNull() ) { - foreach ( const QString &type, d->mimeTypes ) { - if ( mimeType->is( type )) { - found = true; - break; - } - } - } - } - if ( found ) - break; - } - if ( !found ) return false; - } - - if ( !d->capabilities.isEmpty() ) { - bool found = false; - foreach ( const QString &cap, index.data( AgentTypeModel::CapabilitiesRole ).toStringList() ) { - if ( d->capabilities.contains( cap ) ) { - found = true; - break; - } - } - if ( !found ) return false; - } - return true; -} - -#include "agentfilterproxymodel.moc" diff --git a/akonadi/agentfilterproxymodel.h b/akonadi/agentfilterproxymodel.h deleted file mode 100644 index 0229ec4c2..000000000 --- a/akonadi/agentfilterproxymodel.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_AGENTFILTERPROXYMODEL_H -#define AKONADI_AGENTFILTERPROXYMODEL_H - -#include "akonadi_export.h" -#include - -namespace Akonadi { - -/** - * @short A proxy model for filtering AgentType or AgentInstance - * - * This filter proxy model works on top of a AgentTypeModel or AgentInstanceModel - * and can be used to show only AgentType or AgentInstance objects - * which provide a given mime type or capability. - * - * @code - * - * // Show only running agent instances that provide contacts - * Akonadi::AgentInstanceModel *model = new Akonadi::AgentInstanceModel( this ); - * - * Akonadi::AgentFilterProxyModel *proxy = new Akonadi::AgentFilterProxyModel( this ); - * proxy->addMimeTypeFilter( "text/directory" ); - * - * proxy->setSourceModel( model ); - * - * QListView *view = new QListView( this ); - * view->setModel( proxy ); - * - * @endcode - * - * @author Volker Krause - */ -class AKONADI_EXPORT AgentFilterProxyModel : public QSortFilterProxyModel -{ - Q_OBJECT - public: - /** - * Create a new agent filter proxy model. - * By default no filtering is done. - */ - explicit AgentFilterProxyModel( QObject *parent = 0 ); - - /** - * Destroys the agent filter proxy model. - */ - ~AgentFilterProxyModel(); - - /** - * Accept agents supporting @p mimeType. - */ - void addMimeTypeFilter( const QString &mimeType ); - - /** - * Accept agents with the given @p capability. - */ - void addCapabilityFilter( const QString &capability ); - - /** - * Clear the filters ( mimeTypes & capabilities ). - */ - void clearFilters(); - - protected: - bool filterAcceptsRow( int row, const QModelIndex &parent ) const; - - private: - //@cond PRIVATE - class Private; - Private* const d; - //@endcond -}; - -} - -#endif diff --git a/akonadi/agentinstance.cpp b/akonadi/agentinstance.cpp deleted file mode 100644 index 9adbd4f05..000000000 --- a/akonadi/agentinstance.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* - Copyright (c) 2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "agentinstance.h" -#include "agentinstance_p.h" - -#include "agentmanager.h" -#include "agentmanager_p.h" - -using namespace Akonadi; - -AgentInstance::AgentInstance() - : d( new Private ) -{ -} - -AgentInstance::AgentInstance( const AgentInstance &other ) - : d( other.d ) -{ -} - -AgentInstance::~AgentInstance() -{ -} - -bool AgentInstance::isValid() const -{ - return !d->mIdentifier.isEmpty(); -} - - -AgentType AgentInstance::type() const -{ - return d->mType; -} - -QString AgentInstance::identifier() const -{ - return d->mIdentifier; -} - -void AgentInstance::setName( const QString &name ) -{ - AgentManager::self()->d->setName( *this, name ); -} - -QString AgentInstance::name() const -{ - return d->mName; -} - -AgentInstance::Status AgentInstance::status() const -{ - switch ( d->mStatus ) { - case 0: - return Idle; - case 1: - return Running; - case 2: - default: - return Broken; - } -} - -QString AgentInstance::statusMessage() const -{ - return d->mStatusMessage; -} - -int AgentInstance::progress() const -{ - return d->mProgress; -} - -bool AgentInstance::isOnline() const -{ - return d->mIsOnline; -} - -void AgentInstance::setIsOnline( bool online ) -{ - AgentManager::self()->d->setOnline( *this, online ); -} - -void AgentInstance::configure( QWidget *parent ) -{ - AgentManager::self()->d->configure( *this, parent ); -} - -void AgentInstance::synchronize() -{ - AgentManager::self()->d->synchronize( *this ); -} - -void AgentInstance::synchronizeCollectionTree() -{ - AgentManager::self()->d->synchronizeCollectionTree( *this ); -} - -AgentInstance& AgentInstance::operator=( const AgentInstance &other ) -{ - if ( this != &other ) - d = other.d; - - return *this; -} - -bool AgentInstance::operator==( const AgentInstance &other ) const -{ - return (d->mIdentifier == other.d->mIdentifier); -} diff --git a/akonadi/agentinstance.h b/akonadi/agentinstance.h deleted file mode 100644 index 330cd9758..000000000 --- a/akonadi/agentinstance.h +++ /dev/null @@ -1,183 +0,0 @@ -/* - Copyright (c) 2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_AGENTINSTANCE_H -#define AKONADI_AGENTINSTANCE_H - -#include "akonadi_export.h" - -#include -#include -#include - -class QString; -class QStringList; -class QWidget; - -namespace Akonadi -{ - -class AgentType; - -/** - * @short A representation of an agent instance. - * - * The agent instance is a representation of a running agent process. - * It provides information about the instance and a reference to the - * AgentType of that instance. - * - * All available agent instances can be retrieved from the AgentManager. - * - * @code - * - * Akonadi::AgentInstance::List instances = Akonadi::AgentManager::self()->instances(); - * foreach ( const Akonadi::AgentInstance &instance, instances ) { - * qDebug() << "Name:" << instance.name() << "(" << instance.identifier() << ")"; - * } - * - * @endcode - * - * @author Tobias Koenig - */ -class AKONADI_EXPORT AgentInstance -{ - friend class AgentManager; - friend class AgentManagerPrivate; - - public: - /** - * Describes a list of agent instances. - */ - typedef QList List; - - /** - * Describes the status of the agent instance. - */ - enum Status - { - Idle = 0, ///< The agent instance does currently nothing. - Running, ///< The agent instance is working on something. - Broken ///< The agent instance encountered an error state. - }; - - /** - * Creates a new agent instance object. - */ - AgentInstance(); - - /** - * Creates an agent instance from an @p other agent instance. - */ - AgentInstance( const AgentInstance &other ); - - /** - * Destroys the agent instance object. - */ - ~AgentInstance(); - - /** - * Returns whether the agent instance object is valid. - */ - bool isValid() const; - - /** - * Returns the agent type of this instance. - */ - AgentType type() const; - - /** - * Returns the unique identifier of the agent instance. - */ - QString identifier() const; - - /** - * Returns the user visible name of the agent instance. - */ - QString name() const; - - /** - * Sets the user visible @p name of the agent instance. - */ - void setName( const QString &name ); - - /** - * Returns the status of the agent instance. - */ - Status status() const; - - /** - * Returns a textual presentation of the status of the agent instance. - */ - QString statusMessage() const; - - /** - * Returns the progress of the agent instance in percent, or -1 if no - * progress information are available. - */ - int progress() const; - - /** - * Returns whether the agent instance is online currently. - */ - bool isOnline() const; - - /** - * Sets @p online status of the agent instance. - */ - void setIsOnline( bool online ); - - /** - * Triggers the agent instance to show its configuration dialog. - * - * @param parent Parent window for the configuration dialog. - */ - void configure( QWidget *parent = 0 ); - - /** - * Triggers the agent instance to start synchronization. - */ - void synchronize(); - - /** - * Triggers a synchronization of the collection tree by the given agent instance. - */ - void synchronizeCollectionTree(); - - /** - * @internal - */ - AgentInstance& operator=( const AgentInstance &other ); - - /** - * @internal - */ - bool operator==( const AgentInstance &other ) const; - - private: - //@cond PRIVATE - class Private; - QSharedDataPointer d; - //@endcond -}; - -} - -Q_DECLARE_METATYPE( Akonadi::AgentInstance ) - -#endif diff --git a/akonadi/agentinstance_p.h b/akonadi/agentinstance_p.h deleted file mode 100644 index e61d9d2b5..000000000 --- a/akonadi/agentinstance_p.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - Copyright (c) 2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_AGENTINSTANCE_P_H -#define AKONADI_AGENTINSTANCE_P_H - -#include "agenttype.h" - -#include -#include - -namespace Akonadi -{ - -/** - * @internal - */ -class AgentInstance::Private : public QSharedData -{ - public: - Private() - { - } - - Private( const Private &other ) - : QSharedData( other ) - { - mType = other.mType; - mIdentifier = other.mIdentifier; - mName = other.mName; - mStatus = other.mStatus; - mStatusMessage = other.mStatusMessage; - mProgress = other.mProgress; - mIsOnline = other.mIsOnline; - } - - AgentType mType; - QString mIdentifier; - QString mName; - int mStatus; - QString mStatusMessage; - int mProgress; - bool mIsOnline; -}; - -} - -#endif diff --git a/akonadi/agentinstancecreatejob.cpp b/akonadi/agentinstancecreatejob.cpp deleted file mode 100644 index 21adb85c0..000000000 --- a/akonadi/agentinstancecreatejob.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "agentinstancecreatejob.h" -#include "agentmanager.h" -#include "agentmanager_p.h" - -#include "agentinstance.h" - -#include -#include - -#include - -using namespace Akonadi; - -static const int safetyTimeout = 10000; // ms - -/** - * @internal - */ -class AgentInstanceCreateJob::Private -{ - public: - Private( AgentInstanceCreateJob* parent ) : q( parent ), - parentWidget( 0 ), - safetyTimer( 0 ), - doConfig( false ), - tooLate( false ) - { - } - - ~Private() - { - } - - void agentInstanceAdded( const AgentInstance &instance ) - { - if ( agentInstance == instance && !tooLate ) { - safetyTimer->stop(); - if ( doConfig ) { - // return from dbus call first before doing the next one - QTimer::singleShot( 0, q, SLOT( doConfigure() ) ); - } else { - q->emitResult(); - } - } - } - - void doConfigure() - { - agentInstance.configure( parentWidget ); - q->emitResult(); - } - - void timeout() - { - tooLate = true; - q->setError( KJob::UserDefinedError ); - q->setErrorText( i18n( "Agent instance creation timed out." ) ); - q->emitResult(); - } - - void emitResult() - { - q->emitResult(); - } - - AgentInstanceCreateJob* q; - AgentType agentType; - AgentInstance agentInstance; - QWidget* parentWidget; - QTimer *safetyTimer; - bool doConfig; - bool tooLate; -}; - -AgentInstanceCreateJob::AgentInstanceCreateJob(const AgentType & agentType, QObject * parent) : - KJob( parent ), - d( new Private( this ) ) -{ - d->agentType = agentType; - connect( AgentManager::self(), SIGNAL(instanceAdded(const Akonadi::AgentInstance&)), - this, SLOT(agentInstanceAdded(const Akonadi::AgentInstance&)) ); - - d->safetyTimer = new QTimer( this ); - connect( d->safetyTimer, SIGNAL(timeout()), SLOT(timeout()) ); -} - -AgentInstanceCreateJob::~ AgentInstanceCreateJob() -{ - delete d; -} - -void AgentInstanceCreateJob::configure( QWidget *parent ) -{ - d->parentWidget = parent; - d->doConfig = true; -} - -AgentInstance AgentInstanceCreateJob::instance() const -{ - return d->agentInstance; -} - -void AgentInstanceCreateJob::start() -{ - d->agentInstance = AgentManager::self()->d->createInstance( d->agentType ); - if ( !d->agentInstance.isValid() ) { - setError( KJob::UserDefinedError ); - setErrorText( i18n("Unable to create agent instance." ) ); - QTimer::singleShot( 0, this , SLOT(emitResult()) ); - } else { - d->safetyTimer->start( safetyTimeout ); - } -} - -#include "agentinstancecreatejob.moc" diff --git a/akonadi/agentinstancecreatejob.h b/akonadi/agentinstancecreatejob.h deleted file mode 100644 index 7430ad86a..000000000 --- a/akonadi/agentinstancecreatejob.h +++ /dev/null @@ -1,117 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_AGENTINSTANCECREATEJOB_H -#define AKONADI_AGENTINSTANCECREATEJOB_H - -#include "akonadi_export.h" - -#include - -#include - -namespace Akonadi { - -class AgentInstance; - -/** - * @short Job for creating new agent instances. - * - * This class encapsulates the procedure of creating a new agent instance - * and optionally configuring it immediately. - * - * @code - * - * MyClass::MyClass( QWidget *parent ) - * : QWidget( parent ) - * { - * // Get agent type object - * Akonadi::AgentType type = Akonadi::AgentManager::self()->type( "akonadi_vcard_resource" ); - * - * Akonadi::AgentInstanceCreateJob *job = new Akonadi::AgentInstanceCreateJob( type ); - * connect( job, SIGNAL( result( KJob * ) ), - * this, SLOT( slotCreated( KJob * ) ) ); - * - * // use this widget as parent for the config dialog - * job->configure( this ); - * - * job->start(); - * } - * - * ... - * - * void MyClass::slotCreated( KJob *job ) - * { - * Akonadi::AgentInstanceCreateJob *createJob = static_cast( job ); - * - * qDebug() << "Created agent instance:" << createJob->instance().identifier(); - * } - * - * @endcode - * - * @author Volker Krause - */ -class AKONADI_EXPORT AgentInstanceCreateJob : public KJob -{ - Q_OBJECT - public: - /** - * Create a new agent instance creation job. - * @param type The type of the agent to create. - * @param parent The parent object. - */ - explicit AgentInstanceCreateJob( const AgentType &type, QObject *parent = 0 ); - - /** - * Destroys the agent instance creation job. - */ - ~AgentInstanceCreateJob(); - - /** - * Setup the job to show agent configuration dialog once the agent instance - * has been successfully started. - * @param parent The parent window for the configuration dialog. - */ - void configure( QWidget *parent = 0 ); - - /** - * Returns the AgentInstance object of the newly created agent instance. - */ - AgentInstance instance() const; - - /** - * Starts the instance creation. - */ - void start(); - - private: - //@cond PRIVATE - class Private; - Private* const d; - - Q_PRIVATE_SLOT( d, void agentInstanceAdded( const Akonadi::AgentInstance& ) ) - Q_PRIVATE_SLOT( d, void doConfigure() ) - Q_PRIVATE_SLOT( d, void timeout() ) - Q_PRIVATE_SLOT( d, void emitResult() ) - //@endcond -}; - -} - -#endif diff --git a/akonadi/agentinstancemodel.cpp b/akonadi/agentinstancemodel.cpp deleted file mode 100644 index 2df1ce9a2..000000000 --- a/akonadi/agentinstancemodel.cpp +++ /dev/null @@ -1,227 +0,0 @@ -/* - Copyright (c) 2006 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "agentinstancemodel.h" - -#include "agentinstance.h" -#include "agentmanager.h" - -#include -#include - -#include - -using namespace Akonadi; - -/** - * @internal - */ -class AgentInstanceModel::Private -{ - public: - Private( AgentInstanceModel *parent ) - : mParent( parent ) - { - } - - AgentInstanceModel *mParent; - AgentInstance::List mInstances; - - void instanceAdded( const AgentInstance& ); - void instanceRemoved( const AgentInstance& ); - void instanceChanged( const AgentInstance& ); -}; - -void AgentInstanceModel::Private::instanceAdded( const AgentInstance &instance ) -{ - mInstances.append( instance ); - - emit mParent->layoutChanged(); -} - -void AgentInstanceModel::Private::instanceRemoved( const AgentInstance &instance ) -{ - mInstances.removeAll( instance ); - - emit mParent->layoutChanged(); -} - -void AgentInstanceModel::Private::instanceChanged( const AgentInstance &instance ) -{ - for ( int i = 0; i < mInstances.count(); ++i ) { - if ( mInstances[ i ] == instance ) { - mInstances[ i ] = instance; - - const QModelIndex idx = mParent->index( i, 0 ); - emit mParent->dataChanged( idx, idx ); - - return; - } - } -} - - -AgentInstanceModel::AgentInstanceModel( QObject *parent ) - : QAbstractItemModel( parent ), d( new Private( this ) ) -{ - d->mInstances = AgentManager::self()->instances(); - - connect( AgentManager::self(), SIGNAL( instanceAdded( const Akonadi::AgentInstance& ) ), - this, SLOT( instanceAdded( const Akonadi::AgentInstance& ) ) ); - connect( AgentManager::self(), SIGNAL( instanceRemoved( const Akonadi::AgentInstance& ) ), - this, SLOT( instanceRemoved( const Akonadi::AgentInstance& ) ) ); - connect( AgentManager::self(), SIGNAL( instanceStatusChanged( const Akonadi::AgentInstance& ) ), - this, SLOT( instanceChanged( const Akonadi::AgentInstance& ) ) ); - connect( AgentManager::self(), SIGNAL( instanceProgressChanged( const Akonadi::AgentInstance& ) ), - this, SLOT( instanceChanged( const Akonadi::AgentInstance& ) ) ); - connect( AgentManager::self(), SIGNAL( instanceNameChanged( const Akonadi::AgentInstance& ) ), - this, SLOT( instanceChanged( const Akonadi::AgentInstance& ) ) ); -} - -AgentInstanceModel::~AgentInstanceModel() -{ - delete d; -} - -int AgentInstanceModel::columnCount( const QModelIndex& ) const -{ - return 1; -} - -int AgentInstanceModel::rowCount( const QModelIndex& ) const -{ - return d->mInstances.count(); -} - -QVariant AgentInstanceModel::data( const QModelIndex &index, int role ) const -{ - if ( !index.isValid() ) - return QVariant(); - - if ( index.row() < 0 || index.row() >= d->mInstances.count() ) - return QVariant(); - - const AgentInstance &instance = d->mInstances[ index.row() ]; - - switch ( role ) { - case Qt::DisplayRole: - return instance.name(); - case Qt::DecorationRole: - return instance.type().icon(); - case InstanceRole: - { - QVariant var; - var.setValue( instance ); - return var; - } - case InstanceIdentifierRole: - return instance.identifier(); - case Qt::ToolTipRole: - return QString::fromLatin1( "

%1

%2
" ).arg( instance.name(), instance.type().description() ); - case StatusRole: - return instance.status(); - case StatusMessageRole: - return instance.statusMessage(); - case ProgressRole: - return instance.progress(); - case OnlineRole: - return instance.isOnline(); - case TypeRole: - { - QVariant var; - var.setValue( instance.type() ); - return var; - } - case TypeIdentifierRole: - return instance.type().identifier(); - case DescriptionRole: - return instance.type().description(); - case CapabilitiesRole: - return instance.type().capabilities(); - case MimeTypesRole: - return instance.type().mimeTypes(); - } - return QVariant(); -} - -QVariant AgentInstanceModel::headerData( int section, Qt::Orientation orientation, int role ) const -{ - if ( orientation == Qt::Vertical ) - return QVariant(); - - if ( role != Qt::DisplayRole ) - return QVariant(); - - switch ( section ) { - case 0: - return i18nc( "@title:column, name of a thing", "Name" ); - break; - default: - return QVariant(); - break; - } -} - -QModelIndex AgentInstanceModel::index( int row, int column, const QModelIndex& ) const -{ - if ( row < 0 || row >= d->mInstances.count() ) - return QModelIndex(); - - if ( column != 0 ) - return QModelIndex(); - - return createIndex( row, column, 0 ); -} - -QModelIndex AgentInstanceModel::parent( const QModelIndex& ) const -{ - return QModelIndex(); -} - -Qt::ItemFlags AgentInstanceModel::flags( const QModelIndex & index ) const -{ - if ( !index.isValid() || index.row() < 0 || index.row() >= d->mInstances.count() ) - return QAbstractItemModel::flags( index ); - - return QAbstractItemModel::flags( index ) | Qt::ItemIsEditable; -} - -bool AgentInstanceModel::setData( const QModelIndex & index, const QVariant & value, int role ) -{ - if ( !index.isValid() ) - return false; - - if ( index.row() < 0 || index.row() >= d->mInstances.count() ) - return false; - - AgentInstance &instance = d->mInstances[ index.row() ]; - - switch ( role ) { - case OnlineRole: - instance.setIsOnline( value.toBool() ); - emit dataChanged( index, index ); - return true; - default: - return false; - } - - return false; -} - -#include "agentinstancemodel.moc" diff --git a/akonadi/agentinstancemodel.h b/akonadi/agentinstancemodel.h deleted file mode 100644 index 4f7e950cd..000000000 --- a/akonadi/agentinstancemodel.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - Copyright (c) 2006-2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_AGENTINSTANCEMODEL_H -#define AKONADI_AGENTINSTANCEMODEL_H - -#include "akonadi_export.h" - -#include - -namespace Akonadi { - -/** - * @short Provides a data model for agent instances. - * - * This class provides the interface of a QAbstractItemModel to - * access all available agent instances: their name, identifier, - * supported mimetypes and capabilities. - * - * @code - * - * Akonadi::AgentInstanceModel *model = new Akonadi::AgentInstanceModel( this ); - * - * QListView *view = new QListView( this ); - * view->setModel( model ); - * - * @endcode - * - * To show only agent instances that match a given mime type or special - * capabilities, use the AgentFilterProxyModel on top of this model. - * - * @author Tobias Koenig - */ -class AKONADI_EXPORT AgentInstanceModel : public QAbstractItemModel -{ - Q_OBJECT - - public: - /** - * Describes the roles of this model. - */ - enum Roles - { - TypeRole = Qt::UserRole + 1, ///< The agent type itself - TypeIdentifierRole, ///< The identifier of the agent type - DescriptionRole, ///< A description of the agent type - MimeTypesRole, ///< A list of supported mimetypes - CapabilitiesRole, ///< A list of supported capabilities - InstanceRole, ///< The agent instance itself - InstanceIdentifierRole, ///< The identifier of the agent instance - StatusRole, ///< The current status (numerical) of the instance - StatusMessageRole, ///< A textual presentation of the current status - ProgressRole, ///< The current progress (numerical in percent) of an operation - OnlineRole, ///< The current online/offline status - UserRole = Qt::UserRole + 42 ///< Role for user extensions - }; - - /** - * Creates a new agent instance model. - * - * @param parent The parent object. - */ - explicit AgentInstanceModel( QObject *parent = 0 ); - - /** - * Destroys the agent instance model. - */ - virtual ~AgentInstanceModel(); - - virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const; - virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const; - virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const; - virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; - virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const; - virtual QModelIndex parent( const QModelIndex &index ) const; - virtual Qt::ItemFlags flags( const QModelIndex &index ) const; - virtual bool setData( const QModelIndex &index, const QVariant &value, int role ); - - private: - //@cond PRIVATE - class Private; - Private* const d; - - Q_PRIVATE_SLOT( d, void instanceAdded( const Akonadi::AgentInstance& ) ) - Q_PRIVATE_SLOT( d, void instanceRemoved( const Akonadi::AgentInstance& ) ) - Q_PRIVATE_SLOT( d, void instanceChanged( const Akonadi::AgentInstance& ) ) - //@endcond -}; - -} - -#endif diff --git a/akonadi/agentinstancewidget.cpp b/akonadi/agentinstancewidget.cpp deleted file mode 100644 index 66233fdd9..000000000 --- a/akonadi/agentinstancewidget.cpp +++ /dev/null @@ -1,292 +0,0 @@ -/* - Copyright (c) 2006-2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "agentinstancewidget.h" - -#include "agentfilterproxymodel.h" -#include "agentinstance.h" -#include "agentinstancemodel.h" - -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -using namespace Akonadi; - -struct Icons -{ - Icons() - : readyPixmap( KIcon( QLatin1String("user-online") ).pixmap( QSize( 16, 16 ) ) ) - , syncPixmap( KIcon( QLatin1String("network-connect") ).pixmap( QSize( 16, 16 ) ) ) - , errorPixmap( KIcon( QLatin1String("dialog-error") ).pixmap( QSize( 16, 16 ) ) ) - { - } - QPixmap readyPixmap, syncPixmap, errorPixmap; -}; - -K_GLOBAL_STATIC( Icons, s_icons ) - -/** - * @internal - */ -class AgentInstanceWidgetDelegate : public QAbstractItemDelegate -{ - public: - AgentInstanceWidgetDelegate( QObject *parent = 0 ); - - virtual void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const; - virtual QSize sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const; - - private: - void drawFocus( QPainter*, const QStyleOptionViewItem&, const QRect& ) const; - - QTextDocument* document( const QStyleOptionViewItem &option, const QModelIndex &index ) const; -}; - -/** - * @internal - */ -class AgentInstanceWidget::Private -{ - public: - Private( AgentInstanceWidget *parent ) - : mParent( parent ) - { - } - - void currentAgentInstanceChanged( const QModelIndex&, const QModelIndex& ); - void currentAgentInstanceDoubleClicked( const QModelIndex& ); - - AgentInstanceWidget *mParent; - QListView *mView; - AgentInstanceModel *mModel; - AgentFilterProxyModel *proxy; -}; - -void AgentInstanceWidget::Private::currentAgentInstanceChanged( const QModelIndex ¤tIndex, const QModelIndex &previousIndex ) -{ - AgentInstance currentInstance; - if ( currentIndex.isValid() ) - currentInstance = currentIndex.data( AgentInstanceModel::InstanceRole ).value(); - - AgentInstance previousInstance; - if ( previousIndex.isValid() ) - previousInstance = previousIndex.data( AgentInstanceModel::InstanceRole ).value(); - - emit mParent->currentChanged( currentInstance, previousInstance ); -} - -void AgentInstanceWidget::Private::currentAgentInstanceDoubleClicked( const QModelIndex ¤tIndex ) -{ - AgentInstance currentInstance; - if ( currentIndex.isValid() ) - currentInstance = currentIndex.data( AgentInstanceModel::InstanceRole ).value(); - - emit mParent->doubleClicked( currentInstance ); -} - -AgentInstanceWidget::AgentInstanceWidget( QWidget *parent ) - : QWidget( parent ), d( new Private( this ) ) -{ - QHBoxLayout *layout = new QHBoxLayout( this ); - layout->setMargin( 0 ); - layout->setSpacing( 0 ); - - d->mView = new QListView( this ); - d->mView->setItemDelegate( new AgentInstanceWidgetDelegate( d->mView ) ); - layout->addWidget( d->mView ); - - d->mModel = new AgentInstanceModel( this ); - - d->proxy = new AgentFilterProxyModel( this ); - d->proxy->setSourceModel( d->mModel ); - d->mView->setModel( d->proxy ); - - d->mView->selectionModel()->setCurrentIndex( d->mView->model()->index( 0, 0 ), QItemSelectionModel::Select ); - d->mView->scrollTo( d->mView->model()->index( 0, 0 ) ); - - connect( d->mView->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), - this, SLOT( currentAgentInstanceChanged( const QModelIndex&, const QModelIndex& ) ) ); - connect( d->mView, SIGNAL( doubleClicked( const QModelIndex& ) ), - this, SLOT( currentAgentInstanceDoubleClicked( const QModelIndex& ) ) ); -} - -AgentInstanceWidget::~AgentInstanceWidget() -{ - delete d; -} - -AgentInstance AgentInstanceWidget::currentAgentInstance() const -{ - QItemSelectionModel *selectionModel = d->mView->selectionModel(); - if ( !selectionModel ) - return AgentInstance(); - - QModelIndex index = selectionModel->currentIndex(); - if ( !index.isValid() ) - return AgentInstance(); - - return index.data( AgentInstanceModel::InstanceRole ).value(); -} - -AgentFilterProxyModel* AgentInstanceWidget::agentFilterProxyModel() const -{ - return d->proxy; -} - - - - - -AgentInstanceWidgetDelegate::AgentInstanceWidgetDelegate( QObject *parent ) - : QAbstractItemDelegate( parent ) -{ -} - -QTextDocument* AgentInstanceWidgetDelegate::document( const QStyleOptionViewItem &option, const QModelIndex &index ) const -{ - if ( !index.isValid() ) - return 0; - - const QString name = index.model()->data( index, Qt::DisplayRole ).toString(); - int status = index.model()->data( index, AgentInstanceModel::StatusRole ).toInt(); - uint progress = index.model()->data( index, AgentInstanceModel::ProgressRole ).toUInt(); - const QString statusMessage = index.model()->data( index, AgentInstanceModel::StatusMessageRole ).toString(); - const QStringList capabilities = index.model()->data( index, AgentInstanceModel::CapabilitiesRole ).toStringList(); - - QTextDocument *document = new QTextDocument( 0 ); - - const QVariant data = index.model()->data( index, Qt::DecorationRole ); - if ( data.isValid() && data.type() == QVariant::Icon ) { - document->addResource( QTextDocument::ImageResource, QUrl( QLatin1String( "agent_icon" ) ), - qvariant_cast( data ).pixmap( QSize( 64, 64 ) ) ); - } - - if ( status == 0 ) - document->addResource( QTextDocument::ImageResource, QUrl( QLatin1String( "status_icon" ) ), s_icons->readyPixmap ); - else if ( status == 1 ) - document->addResource( QTextDocument::ImageResource, QUrl( QLatin1String( "status_icon" ) ), s_icons->syncPixmap ); - else - document->addResource( QTextDocument::ImageResource, QUrl( QLatin1String( "status_icon" ) ), s_icons->errorPixmap ); - - - QPalette::ColorGroup cg = option.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled; - if ( cg == QPalette::Normal && !(option.state & QStyle::State_Active) ) - cg = QPalette::Inactive; - - QColor textColor; - if ( option.state & QStyle::State_Selected ) { - textColor = option.palette.color( cg, QPalette::HighlightedText ); - } else { - textColor = option.palette.color( cg, QPalette::Text ); - } - - QString content = QString::fromLatin1( - "" - "" - "" - "" - "" - "" - "" ).arg(textColor.name().toUpper()).arg( name ); - if ( capabilities.contains( QLatin1String( "Resource" ) ) ) { - content += QString::fromLatin1( - "" - "" - "" ).arg( statusMessage ).arg( status == 1 ? QString( QLatin1String( "(%1%)" ) ).arg( progress ) : QLatin1String( "" ) ); - } - content += QLatin1String( "
%2
%1 %2
" ); - - document->setHtml( content ); - - return document; -} - -void AgentInstanceWidgetDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const -{ - if ( !index.isValid() ) - return; - - QTextDocument *doc = document( option, index ); - if ( !doc ) - return; - - painter->setRenderHint( QPainter::Antialiasing ); - - QPen pen = painter->pen(); - - QPalette::ColorGroup cg = option.state & QStyle::State_Enabled ? QPalette::Normal : QPalette::Disabled; - if ( cg == QPalette::Normal && !(option.state & QStyle::State_Active) ) - cg = QPalette::Inactive; - - if ( option.state & QStyle::State_Selected ) { - painter->fillRect( option.rect, option.palette.brush( cg, QPalette::Highlight ) ); - painter->setPen( option.palette.color( cg, QPalette::HighlightedText ) ); - } else { - painter->setPen(option.palette.color( cg, QPalette::Text ) ); - } - - painter->save(); - painter->translate( option.rect.topLeft() ); - doc->drawContents( painter ); - delete doc; - painter->restore(); - - painter->setPen(pen); - - drawFocus( painter, option, option.rect ); -} - -QSize AgentInstanceWidgetDelegate::sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const -{ - if ( !index.isValid() ) - return QSize( 0, 0 ); - - QTextDocument *doc = document( option, index ); - if ( !doc ) - return QSize( 0, 0 ); - - const QSize size = doc->documentLayout()->documentSize().toSize(); - delete doc; - - return size; -} - -void AgentInstanceWidgetDelegate::drawFocus( QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect ) const -{ - if ( option.state & QStyle::State_HasFocus ) { - QStyleOptionFocusRect o; - o.QStyleOption::operator=( option ); - o.rect = rect; - o.state |= QStyle::State_KeyboardFocusChange; - QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ? QPalette::Normal : QPalette::Disabled; - o.backgroundColor = option.palette.color( cg, (option.state & QStyle::State_Selected) - ? QPalette::Highlight : QPalette::Background ); - QApplication::style()->drawPrimitive( QStyle::PE_FrameFocusRect, &o, painter ); - } -} - -#include "agentinstancewidget.moc" diff --git a/akonadi/agentinstancewidget.h b/akonadi/agentinstancewidget.h deleted file mode 100644 index f727e802a..000000000 --- a/akonadi/agentinstancewidget.h +++ /dev/null @@ -1,121 +0,0 @@ -/* - Copyright (c) 2006-2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_AGENTINSTANCEWIDGET_H -#define AKONADI_AGENTINSTANCEWIDGET_H - -#include "akonadi_export.h" - -#include - -namespace Akonadi { - -class AgentInstance; -class AgentFilterProxyModel; - -/** - * @short Provides a widget that lists all available agent instances. - * - * The widget is listening on the dbus for changes, so the - * widget is updated automatically as soon as new agent instances - * are added to or removed from the system. - * - * @code - * - * MyWidget::MyWidget( QWidget *parent ) - * : QWidget( parent ) - * { - * QVBoxLayout *layout = new QVBoxLayout( this ); - * - * mAgentInstanceWidget = new Akonadi::AgentInstanceWidget( this ); - * layout->addWidget( mAgentInstanceWidget ); - * - * connect( mAgentInstanceWidget, SIGNAL( doubleClicked( Akonadi::AgentInstance& ) ), - * this, SLOT( slotInstanceSelected( Akonadi::AgentInstance& ) ) ); - * } - * - * ... - * - * MyWidget::slotInstanceSelected( Akonadi::AgentInstance &instance ) - * { - * qDebug() << "Selected instance" << instance.name(); - * } - * - * @endcode - * - * @author Tobias Koenig - */ -class AKONADI_EXPORT AgentInstanceWidget : public QWidget -{ - Q_OBJECT - - public: - /** - * Creates a new agent instance widget. - * - * @param parent The parent widget. - */ - explicit AgentInstanceWidget( QWidget *parent = 0 ); - - /** - * Destroys the agent instance widget. - */ - ~AgentInstanceWidget(); - - /** - * Returns the current agent instance or an invalid agent instance - * if no agent instance is selected. - */ - AgentInstance currentAgentInstance() const; - - /** - Returns the agent filter proxy model, use this to filter by - agent mimetype or capabilities. - */ - AgentFilterProxyModel* agentFilterProxyModel() const; - - Q_SIGNALS: - /** - * This signal is emitted whenever the current agent instance changes. - * - * @param current The current agent instance. - * @param previous The previous agent instance. - */ - void currentChanged( const Akonadi::AgentInstance ¤t, const Akonadi::AgentInstance &previous ); - - /** - * This signal is emitted whenever the there is a double click on an agent instance. - * - * @param current The current agent instance. - */ - void doubleClicked( const Akonadi::AgentInstance ¤t ); - - private: - //@cond PRIVATE - class Private; - Private* const d; - - Q_PRIVATE_SLOT( d, void currentAgentInstanceChanged( const QModelIndex&, const QModelIndex& ) ) - Q_PRIVATE_SLOT( d, void currentAgentInstanceDoubleClicked( const QModelIndex& ) ) - //@endcond -}; - -} - -#endif diff --git a/akonadi/agentmanager.cpp b/akonadi/agentmanager.cpp deleted file mode 100644 index f12d9b171..000000000 --- a/akonadi/agentmanager.cpp +++ /dev/null @@ -1,290 +0,0 @@ -/* - Copyright (c) 2006-2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "agentmanager.h" -#include "agentmanager_p.h" - -#include "agenttype_p.h" -#include "agentinstance_p.h" - -#include "collection.h" - -#include - - -using namespace Akonadi; - -AgentInstance AgentManagerPrivate::createInstance( const AgentType &type ) -{ - const QString &identifier = mManager->createAgentInstance( type.identifier() ); - if ( identifier.isEmpty() ) - return AgentInstance(); - - return fillAgentInstanceLight( identifier ); -} - -void AgentManagerPrivate::agentTypeAdded( const QString &identifier ) -{ - const AgentType type = fillAgentType( identifier ); - if ( type.isValid() ) { - mTypes.insert( identifier, type ); - emit mParent->typeAdded( type ); - } -} - -void AgentManagerPrivate::agentTypeRemoved( const QString &identifier ) -{ - if ( !mTypes.contains( identifier ) ) - return; - - const AgentType type = mTypes.take( identifier ); - emit mParent->typeRemoved( type ); -} - -void AgentManagerPrivate::agentInstanceAdded( const QString &identifier ) -{ - const AgentInstance instance = fillAgentInstance( identifier ); - if ( instance.isValid() ) { - mInstances.insert( identifier, instance ); - emit mParent->instanceAdded( instance ); - } -} - -void AgentManagerPrivate::agentInstanceRemoved( const QString &identifier ) -{ - if ( !mInstances.contains( identifier ) ) - return; - - const AgentInstance instance = mInstances.take( identifier ); - emit mParent->instanceRemoved( instance ); -} - -void AgentManagerPrivate::agentInstanceStatusChanged( const QString &identifier, int status, const QString &msg ) -{ - if ( !mInstances.contains( identifier ) ) - return; - - AgentInstance &instance = mInstances[ identifier ]; - instance.d->mStatus = status; - instance.d->mStatusMessage = msg; - - emit mParent->instanceStatusChanged( instance ); -} - -void AgentManagerPrivate::agentInstanceProgressChanged( const QString &identifier, uint progress, const QString &msg ) -{ - if ( !mInstances.contains( identifier ) ) - return; - - AgentInstance &instance = mInstances[ identifier ]; - instance.d->mProgress = progress; - instance.d->mStatusMessage = msg; - - emit mParent->instanceProgressChanged( instance ); -} - -void AgentManagerPrivate::agentInstanceWarning( const QString &identifier, const QString &msg ) -{ - if ( !mInstances.contains( identifier ) ) - return; - - AgentInstance &instance = mInstances[ identifier ]; - emit mParent->instanceWarning( instance, msg ); -} - -void AgentManagerPrivate::agentInstanceError( const QString &identifier, const QString &msg ) -{ - if ( !mInstances.contains( identifier ) ) - return; - - AgentInstance &instance = mInstances[ identifier ]; - emit mParent->instanceError( instance, msg ); -} - -void AgentManagerPrivate::agentInstanceNameChanged( const QString &identifier, const QString &name ) -{ - if ( !mInstances.contains( identifier ) ) - return; - - AgentInstance &instance = mInstances[ identifier ]; - instance.d->mName = name; - - emit mParent->instanceNameChanged( instance ); -} - -AgentType AgentManagerPrivate::fillAgentType( const QString &identifier ) const -{ - AgentType type; - type.d->mIdentifier = identifier; - type.d->mName = mManager->agentName( identifier ); - type.d->mDescription = mManager->agentComment( identifier ); - type.d->mIconName = mManager->agentIcon( identifier ); - type.d->mMimeTypes = mManager->agentMimeTypes( identifier ); - type.d->mCapabilities = mManager->agentCapabilities( identifier ); - - return type; -} - -void AgentManagerPrivate::setName( const AgentInstance &instance, const QString &name ) -{ - mManager->setAgentInstanceName( instance.identifier(), name ); -} - -void AgentManagerPrivate::setOnline( const AgentInstance &instance, bool state ) -{ - mManager->setAgentInstanceOnline( instance.identifier(), state ); -} - -void AgentManagerPrivate::configure( const AgentInstance &instance, QWidget *parent ) -{ - qlonglong winId = 0; - if ( parent ) - winId = (qlonglong)( parent->window()->winId() ); - - mManager->agentInstanceConfigure( instance.identifier(), winId ); -} - -void AgentManagerPrivate::synchronize( const AgentInstance &instance ) -{ - mManager->agentInstanceSynchronize( instance.identifier() ); -} - -void AgentManagerPrivate::synchronizeCollectionTree( const AgentInstance &instance ) -{ - mManager->agentInstanceSynchronizeCollectionTree( instance.identifier() ); -} - -AgentInstance AgentManagerPrivate::fillAgentInstance( const QString &identifier ) const -{ - AgentInstance instance; - - const QString agentTypeIdentifier = mManager->agentInstanceType( identifier ); - Q_ASSERT_X( mTypes.contains( agentTypeIdentifier ), "fillAgentInstance", "Requests non-existing agent type" ); - - instance.d->mType = mTypes.value( agentTypeIdentifier ); - instance.d->mIdentifier = identifier; - instance.d->mName = mManager->agentInstanceName( identifier ); - instance.d->mStatus = mManager->agentInstanceStatus( identifier ); - instance.d->mStatusMessage = mManager->agentInstanceStatusMessage( identifier ); - instance.d->mProgress = mManager->agentInstanceProgress( identifier ); - instance.d->mIsOnline = mManager->agentInstanceOnline( identifier ); - - return instance; -} - -AgentInstance AgentManagerPrivate::fillAgentInstanceLight( const QString &identifier ) const -{ - AgentInstance instance; - - const QString agentTypeIdentifier = mManager->agentInstanceType( identifier ); - Q_ASSERT_X( mTypes.contains( agentTypeIdentifier ), "fillAgentInstanceLight", "Requests non-existing agent type" ); - - instance.d->mType = mTypes.value( agentTypeIdentifier ); - instance.d->mIdentifier = identifier; - - return instance; -} - -AgentManager* AgentManagerPrivate::mSelf = 0; - -AgentManager::AgentManager() - : QObject( 0 ), d( new AgentManagerPrivate( this ) ) -{ - d->mManager = new org::freedesktop::Akonadi::AgentManager( QLatin1String( "org.freedesktop.Akonadi.Control" ), - QLatin1String( "/AgentManager" ), - QDBusConnection::sessionBus(), this ); - - connect( d->mManager, SIGNAL( agentTypeAdded( const QString& ) ), - this, SLOT( agentTypeAdded( const QString& ) ) ); - connect( d->mManager, SIGNAL( agentTypeRemoved( const QString& ) ), - this, SLOT( agentTypeRemoved( const QString& ) ) ); - connect( d->mManager, SIGNAL( agentInstanceAdded( const QString& ) ), - this, SLOT( agentInstanceAdded( const QString& ) ) ); - connect( d->mManager, SIGNAL( agentInstanceRemoved( const QString& ) ), - this, SLOT( agentInstanceRemoved( const QString& ) ) ); - connect( d->mManager, SIGNAL( agentInstanceStatusChanged( const QString&, int, const QString& ) ), - this, SLOT( agentInstanceStatusChanged( const QString&, int, const QString& ) ) ); - connect( d->mManager, SIGNAL( agentInstanceProgressChanged( const QString&, uint, const QString& ) ), - this, SLOT( agentInstanceProgressChanged( const QString&, uint, const QString& ) ) ); - connect( d->mManager, SIGNAL( agentInstanceNameChanged( const QString&, const QString& ) ), - this, SLOT( agentInstanceNameChanged( const QString&, const QString& ) ) ); - connect( d->mManager, SIGNAL( agentInstanceWarning( const QString&, const QString& ) ), - this, SLOT( agentInstanceWarning( const QString&, const QString& ) ) ); - connect( d->mManager, SIGNAL( agentInstanceError( const QString&, const QString& ) ), - this, SLOT( agentInstanceError( const QString&, const QString& ) ) ); - - const QStringList typeIdentifiers = d->mManager->agentTypes(); - foreach( const QString &type, typeIdentifiers ) { - const AgentType agentType = d->fillAgentType( type ); - d->mTypes.insert( type, agentType ); - } - - const QStringList instanceIdentifiers = d->mManager->agentInstances(); - foreach( const QString &instance, instanceIdentifiers ) { - const AgentInstance agentInstance = d->fillAgentInstance( instance ); - d->mInstances.insert( instance, agentInstance ); - } -} - -AgentManager::~AgentManager() -{ - delete d; -} - -AgentManager* AgentManager::self() -{ - if ( !AgentManagerPrivate::mSelf ) - AgentManagerPrivate::mSelf = new AgentManager(); - - return AgentManagerPrivate::mSelf; -} - -AgentType::List AgentManager::types() const -{ - return d->mTypes.values(); -} - -AgentType AgentManager::type( const QString &identifier ) const -{ - return d->mTypes.value( identifier ); -} - -AgentInstance::List AgentManager::instances() const -{ - return d->mInstances.values(); -} - -AgentInstance AgentManager::instance( const QString &identifier ) const -{ - return d->mInstances.value( identifier ); -} - -void AgentManager::removeInstance( const AgentInstance &instance ) -{ - d->mManager->removeAgentInstance( instance.identifier() ); -} - -void AgentManager::synchronizeCollection(const Collection & collection) -{ - const QString resId = collection.resource(); - Q_ASSERT( !resId.isEmpty() ); - d->mManager->agentInstanceSynchronizeCollection( resId, collection.id() ); -} - -#include "agentmanager.moc" diff --git a/akonadi/agentmanager.h b/akonadi/agentmanager.h deleted file mode 100644 index 1cd02ff92..000000000 --- a/akonadi/agentmanager.h +++ /dev/null @@ -1,196 +0,0 @@ -/* - Copyright (c) 2006-2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_AGENTMANAGER_H -#define AKONADI_AGENTMANAGER_H - -#include "akonadi_export.h" - -#include -#include - -#include - -namespace Akonadi { - -class AgentManagerPrivate; -class Collection; - -/** - * @short Provides an interface to retrieve agent types and manage agent instances. - * - * This singleton class can be used to create or remove agent instances or trigger - * synchronization of collections. Furthermore it provides information about status - * changes of the agents. - * - * @code - * - * Akonadi::AgentManager *manager = Akonadi::AgentManager::self(); - * - * Akonadi::AgentType::List types = manager->types(); - * foreach( const Akonadi::AgentType type&, types ) { - * qDebug() << "Type:" << type.name() << type.description(); - * } - * - * @endcode - * - * @author Tobias Koenig - */ -class AKONADI_EXPORT AgentManager : public QObject -{ - friend class AgentInstance; - friend class AgentInstanceCreateJob; - friend class AgentManagerPrivate; - - Q_OBJECT - - public: - /** - * Returns the global instance of the agent manager. - */ - static AgentManager *self(); - - /** - * Destroys the agent manager. - */ - ~AgentManager(); - - /** - * Returns the list of all available agent types. - */ - AgentType::List types() const; - - /** - * Returns the agent type with the given @p identifier or - * an invalid agent type if the identifier does not exist. - */ - AgentType type( const QString &identififer ) const; - - /** - * Returns the list of all available agent instances. - */ - AgentInstance::List instances() const; - - /** - * Returns the agent instance with the given @p identifier or - * an invalid agent instance if the identifier does not exist. - */ - AgentInstance instance( const QString &identififer ) const; - - /** - * Removes the given agent @p instance. - */ - void removeInstance( const AgentInstance &instance ); - - /** - * Trigger a synchronization of the given collection by its owning resource agent. - * - * @param collection The collection to synchronize. - */ - void synchronizeCollection( const Collection &collection ); - - Q_SIGNALS: - /** - * This signal is emitted whenever a new agent type was installed on the system. - * - * @param type The new agent type. - */ - void typeAdded( const Akonadi::AgentType &type ); - - /** - * This signal is emitted whenever an agent type was removed from the system. - * - * @param type The removed agent type. - */ - void typeRemoved( const Akonadi::AgentType &type ); - - /** - * This signal is emitted whenever a new agent instance was created. - * - * @param instance The new agent instance. - */ - void instanceAdded( const Akonadi::AgentInstance &instance ); - - /** - * This signal is emitted whenever an agent instance was removed. - * - * @param instance The removed agent instance. - */ - void instanceRemoved( const Akonadi::AgentInstance &instance ); - - /** - * This signal is emitted whenever the status of an agent instance has - * changed. - * - * @param instance The agent instance that status has changed. - */ - void instanceStatusChanged( const Akonadi::AgentInstance &instance ); - - /** - * This signal is emitted whenever the progress of an agent instance has - * changed. - * - * @param instance The agent instance that progress has changed. - */ - void instanceProgressChanged( const Akonadi::AgentInstance &instance ); - - /** - * This signal is emitted whenever the name of the agent instance has changed. - * - * @param instance The agent instance that name has changed. - */ - void instanceNameChanged( const Akonadi::AgentInstance &instance ); - - /** - * This signal is emitted whenever the agent instance raised an error. - * - * @param instance The agent instance that raised the error. - * @param message The i18n'ed error message. - */ - void instanceError( const Akonadi::AgentInstance &instance, const QString &message ); - - /** - * This signal is emitted whenever the agent instance raised a warning. - * - * @param instance The agent instance that raised the warning. - * @param message The i18n'ed warning message. - */ - void instanceWarning( const Akonadi::AgentInstance &instance, const QString &message ); - - private: - //@cond PRIVATE - AgentManager(); - - AgentManagerPrivate* const d; - - Q_PRIVATE_SLOT( d, void agentTypeAdded( const QString& ) ) - Q_PRIVATE_SLOT( d, void agentTypeRemoved( const QString& ) ) - Q_PRIVATE_SLOT( d, void agentInstanceAdded( const QString& ) ) - Q_PRIVATE_SLOT( d, void agentInstanceRemoved( const QString& ) ) - Q_PRIVATE_SLOT( d, void agentInstanceStatusChanged( const QString&, int, const QString& ) ) - Q_PRIVATE_SLOT( d, void agentInstanceProgressChanged( const QString&, uint, const QString& ) ) - Q_PRIVATE_SLOT( d, void agentInstanceNameChanged( const QString&, const QString& ) ) - Q_PRIVATE_SLOT( d, void agentInstanceWarning( const QString&, const QString& ) ) - Q_PRIVATE_SLOT( d, void agentInstanceError( const QString&, const QString& ) ) - //@endcond -}; - -} - -#endif diff --git a/akonadi/agentmanager_p.h b/akonadi/agentmanager_p.h deleted file mode 100644 index ba301c452..000000000 --- a/akonadi/agentmanager_p.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - Copyright (c) 2006-2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_AGENTMANAGER_P_H -#define AKONADI_AGENTMANAGER_P_H - -#include "agentmanagerinterface.h" - -#include "agenttype.h" -#include "agentinstance.h" - -#include - -namespace Akonadi { - -class AgentManager; - -/** - * @internal - */ -class AgentManagerPrivate -{ - friend class AgentManager; - - public: - AgentManagerPrivate( AgentManager *parent ) - : mParent( parent ) - { - } - - /* - * Used by AgentInstanceCreateJob - */ - AgentInstance createInstance( const AgentType &type ); - - void agentTypeAdded( const QString& ); - void agentTypeRemoved( const QString& ); - void agentInstanceAdded( const QString& ); - void agentInstanceRemoved( const QString& ); - void agentInstanceStatusChanged( const QString&, int, const QString& ); - void agentInstanceProgressChanged( const QString&, uint, const QString& ); - void agentInstanceNameChanged( const QString&, const QString& ); - void agentInstanceWarning( const QString&, const QString& ); - void agentInstanceError( const QString&, const QString& ); - - void setName( const AgentInstance&, const QString& ); - void setOnline( const AgentInstance&, bool ); - void configure( const AgentInstance&, QWidget* ); - void synchronize( const AgentInstance& ); - void synchronizeCollectionTree( const AgentInstance& ); - - AgentType fillAgentType( const QString &identifier ) const; - AgentInstance fillAgentInstance( const QString &identifier ) const; - AgentInstance fillAgentInstanceLight( const QString &identifier ) const; - - static AgentManager *mSelf; - - AgentManager *mParent; - org::freedesktop::Akonadi::AgentManager *mManager; - - QHash mTypes; - QHash mInstances; -}; - -} - -#endif diff --git a/akonadi/agenttype.cpp b/akonadi/agenttype.cpp deleted file mode 100644 index 0d235befb..000000000 --- a/akonadi/agenttype.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - Copyright (c) 2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "agenttype.h" -#include "agenttype_p.h" - -#include - -using namespace Akonadi; - -AgentType::AgentType() - : d( new Private ) -{ -} - -AgentType::AgentType( const AgentType &other ) - : d( other.d ) -{ -} - -AgentType::~AgentType() -{ -} - -bool AgentType::isValid() const -{ - return !d->mIdentifier.isEmpty(); -} - -QString AgentType::identifier() const -{ - return d->mIdentifier; -} - -QString AgentType::name() const -{ - return d->mName; -} - -QString AgentType::description() const -{ - return d->mDescription; -} - -QString AgentType::iconName() const -{ - return d->mIconName; -} - -QIcon AgentType::icon() const -{ - return KIcon( d->mIconName ); -} - -QStringList AgentType::mimeTypes() const -{ - return d->mMimeTypes; -} - -QStringList AgentType::capabilities() const -{ - return d->mCapabilities; -} - -AgentType& AgentType::operator=( const AgentType &other ) -{ - if ( this != &other ) - d = other.d; - - return *this; -} - -bool AgentType::operator==( const AgentType &other ) const -{ - return (d->mIdentifier == other.d->mIdentifier); -} diff --git a/akonadi/agenttype.h b/akonadi/agenttype.h deleted file mode 100644 index ecced355d..000000000 --- a/akonadi/agenttype.h +++ /dev/null @@ -1,143 +0,0 @@ -/* - Copyright (c) 2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_AGENTTYPE_H -#define AKONADI_AGENTTYPE_H - -#include "akonadi_export.h" - -#include -#include -#include - -class QIcon; -class QString; -class QStringList; - -namespace Akonadi -{ - -/** - * @short A representation of an agent type. - * - * The agent type is a representation of an available agent, that can - * be started as an agent instance. - * It provides all information about the type. - * - * All available agent types can be retrieved from the AgentManager. - * - * @code - * - * Akonadi::AgentType::List types = Akonadi::AgentManager::self()->types(); - * foreach ( const Akonadi::AgentType &type, types ) { - * qDebug() << "Name:" << type.name() << "(" << type.identifier() << ")"; - * } - * - * @endcode - * - * @author Tobias Koenig - */ -class AKONADI_EXPORT AgentType -{ - friend class AgentManager; - friend class AgentManagerPrivate; - - public: - /** - * Describes a list of agent types. - */ - typedef QList List; - - /** - * Creates a new agent type. - */ - AgentType(); - - /** - * Creates an agent type from an @p other agent type. - */ - AgentType( const AgentType &other ); - - /** - * Destroys the agent type. - */ - ~AgentType(); - - /** - * Returns whether the agent type is valid. - */ - bool isValid() const; - - /** - * Returns the unique identifier of the agent type. - */ - QString identifier() const; - - /** - * Returns the i18n'ed name of the agent type. - */ - QString name() const; - - /** - * Returns the description of the agent type. - */ - QString description() const; - - /** - * Returns the name of the icon of the agent type. - */ - QString iconName() const; - - /** - * Returns the icon of the agent type. - */ - QIcon icon() const; - - /** - * Returns the list of supported mime types of the agent type. - */ - QStringList mimeTypes() const; - - /** - * Returns the list of supported capabilities of the agent type. - */ - QStringList capabilities() const; - - /** - * @internal - */ - AgentType& operator=( const AgentType &other ); - - /** - * @internal - */ - bool operator==( const AgentType &other ) const; - - private: - //@cond PRIVATE - class Private; - QSharedDataPointer d; - //@endcond -}; - -} - -Q_DECLARE_METATYPE( Akonadi::AgentType ) - -#endif diff --git a/akonadi/agenttype_p.h b/akonadi/agenttype_p.h deleted file mode 100644 index 05a8efd39..000000000 --- a/akonadi/agenttype_p.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - Copyright (c) 2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_AGENTTYPE_P_H -#define AKONADI_AGENTTYPE_P_H - -#include -#include - -namespace Akonadi -{ - -/** - * @internal - */ -class AgentType::Private : public QSharedData -{ - public: - Private() - { - } - - Private( const Private &other ) - : QSharedData( other ) - { - mIdentifier = other.mIdentifier; - mName = other.mName; - mDescription = other.mDescription; - mIconName = other.mIconName; - mMimeTypes = other.mMimeTypes; - mCapabilities = other.mCapabilities; - } - - QString mIdentifier; - QString mName; - QString mDescription; - QString mIconName; - QStringList mMimeTypes; - QStringList mCapabilities; -}; - -} - -#endif diff --git a/akonadi/agenttypemodel.cpp b/akonadi/agenttypemodel.cpp deleted file mode 100644 index 00fae3c0f..000000000 --- a/akonadi/agenttypemodel.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/* - Copyright (c) 2006 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "agenttypemodel.h" -#include "agenttype.h" -#include "agentmanager.h" - -#include -#include - -using namespace Akonadi; - -/** - * @internal - */ -class AgentTypeModel::Private -{ - public: - Private( AgentTypeModel *parent ) - : mParent( parent ) - { - mTypes = AgentManager::self()->types(); - } - - AgentTypeModel *mParent; - AgentType::List mTypes; - - void typeAdded( const AgentType &agentType ); - void typeRemoved( const AgentType &agentType ); -}; - -void AgentTypeModel::Private::typeAdded( const AgentType &agentType ) -{ - mTypes.append( agentType ); - - emit mParent->layoutChanged(); -} - -void AgentTypeModel::Private::typeRemoved( const AgentType &agentType ) -{ - mTypes.removeAll( agentType ); - - emit mParent->layoutChanged(); -} - -AgentTypeModel::AgentTypeModel( QObject *parent ) - : QAbstractItemModel( parent ), d( new Private( this ) ) -{ - connect( AgentManager::self(), SIGNAL( typeAdded( const Akonadi::AgentType& ) ), - this, SLOT( typeAdded( const Akonadi::AgentType& ) ) ); - connect( AgentManager::self(), SIGNAL( typeRemoved( const Akonadi::AgentType& ) ), - this, SLOT( typeRemoved( const Akonadi::AgentType& ) ) ); -} - -AgentTypeModel::~AgentTypeModel() -{ - delete d; -} - -int AgentTypeModel::columnCount( const QModelIndex& ) const -{ - return 1; -} - -int AgentTypeModel::rowCount( const QModelIndex& ) const -{ - return d->mTypes.count(); -} - -QVariant AgentTypeModel::data( const QModelIndex &index, int role ) const -{ - if ( !index.isValid() ) - return QVariant(); - - if ( index.row() < 0 || index.row() >= d->mTypes.count() ) - return QVariant(); - - const AgentType &type = d->mTypes[ index.row() ]; - - switch ( role ) { - case Qt::DisplayRole: - return type.name(); - break; - case Qt::DecorationRole: - return type.icon(); - break; - case TypeRole: - { - QVariant var; - var.setValue( type ); - return var; - } - break; - case IdentifierRole: - return type.identifier(); - break; - case DescriptionRole: - return type.description(); - break; - case MimeTypesRole: - return type.mimeTypes(); - break; - case CapabilitiesRole: - return type.capabilities(); - break; - default: - break; - } - return QVariant(); -} - -QModelIndex AgentTypeModel::index( int row, int column, const QModelIndex& ) const -{ - if ( row < 0 || row >= d->mTypes.count() ) - return QModelIndex(); - - if ( column != 0 ) - return QModelIndex(); - - return createIndex( row, column, 0 ); -} - -QModelIndex AgentTypeModel::parent( const QModelIndex& ) const -{ - return QModelIndex(); -} - -#include "agenttypemodel.moc" diff --git a/akonadi/agenttypemodel.h b/akonadi/agenttypemodel.h deleted file mode 100644 index 9c070c76a..000000000 --- a/akonadi/agenttypemodel.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - Copyright (c) 2006-2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_AGENTTYPEMODEL_H -#define AKONADI_AGENTTYPEMODEL_H - -#include "akonadi_export.h" - -#include - -namespace Akonadi { - -/** - * @short Provides a data model for agent types. - * - * This class provides the interface of a QAbstractItemModel to - * access all available agent types: their name, identifier, - * supported mimetypes and capabilities. - * - * @code - * - * Akonadi::AgentTypeModel *model = new Akonadi::AgentTypeModel( this ); - * - * QListView *view = new QListView( this ); - * view->setModel( model ); - * - * @endcode - * - * To show only agent types that match a given mime type or special - * capabilities, use the AgentFilterProxyModel on top of this model. - * - * @author Tobias Koenig - */ -class AKONADI_EXPORT AgentTypeModel : public QAbstractItemModel -{ - Q_OBJECT - - public: - /** - * Describes the roles of this model. - */ - enum Roles - { - TypeRole = Qt::UserRole + 1, ///< The agent type itself - IdentifierRole, ///< The identifier of the agent type - DescriptionRole, ///< A description of the agent type - MimeTypesRole, ///< A list of supported mimetypes - CapabilitiesRole, ///< A list of supported capabilities - UserRole = Qt::UserRole + 42 ///< Role for user extensions - }; - - /** - * Creates a new agent type model. - */ - explicit AgentTypeModel( QObject *parent = 0 ); - - /** - * Destroys the agent type model. - */ - virtual ~AgentTypeModel(); - - virtual int columnCount( const QModelIndex &parent = QModelIndex() ) const; - virtual int rowCount( const QModelIndex &parent = QModelIndex() ) const; - virtual QVariant data( const QModelIndex &index, int role = Qt::DisplayRole ) const; - virtual QModelIndex index( int row, int column, const QModelIndex &parent = QModelIndex() ) const; - virtual QModelIndex parent( const QModelIndex &index ) const; - - private: - //@cond PRIVATE - class Private; - Private* const d; - - Q_PRIVATE_SLOT( d, void typeAdded( const Akonadi::AgentType& ) ) - Q_PRIVATE_SLOT( d, void typeRemoved( const Akonadi::AgentType& ) ) - //@endcond -}; - -} - -#endif diff --git a/akonadi/agenttypewidget.cpp b/akonadi/agenttypewidget.cpp deleted file mode 100644 index 29fdf1bea..000000000 --- a/akonadi/agenttypewidget.cpp +++ /dev/null @@ -1,243 +0,0 @@ -/* - Copyright (c) 2006-2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "agenttypewidget.h" - -#include -#include -#include -#include - -#include "agentfilterproxymodel.h" -#include "agenttype.h" -#include "agenttypemodel.h" - -using namespace Akonadi; - -/** - * @internal - */ -class AgentTypeWidgetDelegate : public QAbstractItemDelegate -{ - public: - AgentTypeWidgetDelegate( QObject *parent = 0 ); - - virtual void paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const; - virtual QSize sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const; - - private: - void drawFocus( QPainter*, const QStyleOptionViewItem&, const QRect& ) const; -}; - - -/** - * @internal - */ -class AgentTypeWidget::Private -{ - public: - Private( AgentTypeWidget *parent ) - : mParent( parent ) - { - } - - void currentAgentTypeChanged( const QModelIndex&, const QModelIndex& ); - - AgentTypeWidget *mParent; - QListView *mView; - AgentTypeModel *mModel; - AgentFilterProxyModel *proxyModel; -}; - -void AgentTypeWidget::Private::currentAgentTypeChanged( const QModelIndex ¤tIndex, const QModelIndex &previousIndex ) -{ - AgentType currentType; - if ( currentIndex.isValid() ) - currentType = currentIndex.data( AgentTypeModel::TypeRole ).value(); - - AgentType previousType; - if ( previousIndex.isValid() ) - previousType = previousIndex.data( AgentTypeModel::TypeRole ).value(); - - emit mParent->currentChanged( currentType, previousType ); -} - -AgentTypeWidget::AgentTypeWidget( QWidget *parent ) - : QWidget( parent ), d( new Private( this ) ) -{ - QHBoxLayout *layout = new QHBoxLayout( this ); - layout->setMargin( 0 ); - layout->setSpacing( 0 ); - - d->mView = new QListView( this ); - d->mView->setItemDelegate( new AgentTypeWidgetDelegate( d->mView ) ); - layout->addWidget( d->mView ); - - d->mModel = new AgentTypeModel( d->mView ); - d->proxyModel = new AgentFilterProxyModel( this ); - d->proxyModel->setSourceModel( d->mModel ); - d->mView->setModel( d->proxyModel ); - - d->mView->selectionModel()->setCurrentIndex( d->mView->model()->index( 0, 0 ), QItemSelectionModel::Select ); - d->mView->scrollTo( d->mView->model()->index( 0, 0 ) ); - connect( d->mView->selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), - this, SLOT( currentAgentTypeChanged( const QModelIndex&, const QModelIndex& ) ) ); -} - -AgentTypeWidget::~AgentTypeWidget() -{ - delete d; -} - -AgentType AgentTypeWidget::currentAgentType() const -{ - QItemSelectionModel *selectionModel = d->mView->selectionModel(); - if ( !selectionModel ) - return AgentType(); - - QModelIndex index = selectionModel->currentIndex(); - if ( !index.isValid() ) - return AgentType(); - - return index.data( AgentTypeModel::TypeRole ).value(); -} - -AgentFilterProxyModel* AgentTypeWidget::agentFilterProxyModel() const -{ - return d->proxyModel; -} - -/** - * AgentTypeWidgetDelegate - */ - -AgentTypeWidgetDelegate::AgentTypeWidgetDelegate( QObject *parent ) - : QAbstractItemDelegate( parent ) -{ -} - -void AgentTypeWidgetDelegate::paint( QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index ) const -{ - if ( !index.isValid() ) - return; - - painter->setRenderHint( QPainter::Antialiasing ); - - const QString name = index.model()->data( index, Qt::DisplayRole ).toString(); - const QString comment = index.model()->data( index, AgentTypeModel::DescriptionRole ).toString(); - - const QVariant data = index.model()->data( index, Qt::DecorationRole ); - - QPixmap pixmap; - if ( data.isValid() && data.type() == QVariant::Icon ) - pixmap = qvariant_cast( data ).pixmap( 64, 64 ); - - const QFont oldFont = painter->font(); - QFont boldFont( oldFont ); - boldFont.setBold( true ); - painter->setFont( boldFont ); - QFontMetrics fm = painter->fontMetrics(); - int hn = fm.boundingRect( 0, 0, 0, 0, Qt::AlignLeft, name ).height(); - int wn = fm.boundingRect( 0, 0, 0, 0, Qt::AlignLeft, name ).width(); - painter->setFont( oldFont ); - - fm = painter->fontMetrics(); - int hc = fm.boundingRect( 0, 0, 0, 0, Qt::AlignLeft, comment ).height(); - int wc = fm.boundingRect( 0, 0, 0, 0, Qt::AlignLeft, comment ).width(); - int wp = pixmap.width(); - - QPen pen = painter->pen(); - QPalette::ColorGroup cg = option.state & QStyle::State_Enabled - ? QPalette::Normal : QPalette::Disabled; - if (cg == QPalette::Normal && !(option.state & QStyle::State_Active)) - cg = QPalette::Inactive; - if (option.state & QStyle::State_Selected) { - painter->fillRect(option.rect, option.palette.brush(cg, QPalette::Highlight)); - painter->setPen(option.palette.color(cg, QPalette::HighlightedText)); - } else { - painter->setPen(option.palette.color(cg, QPalette::Text)); - } - - QFont font = painter->font(); - painter->setFont(option.font); - - painter->drawPixmap( option.rect.x() + 5, option.rect.y() + 5, pixmap ); - - painter->setFont(boldFont); - if ( !name.isEmpty() ) - painter->drawText( option.rect.x() + 5 + wp + 5, option.rect.y() + 7, wn, hn, Qt::AlignLeft, name ); - painter->setFont(oldFont); - - if ( !comment.isEmpty() ) - painter->drawText( option.rect.x() + 5 + wp + 5, option.rect.y() + 7 + hn, wc, hc, Qt::AlignLeft, comment ); - - painter->setPen(pen); - - drawFocus( painter, option, option.rect ); -} - -QSize AgentTypeWidgetDelegate::sizeHint( const QStyleOptionViewItem &option, const QModelIndex &index ) const -{ - if ( !index.isValid() ) - return QSize( 0, 0 ); - - const QString name = index.model()->data( index, Qt::DisplayRole ).toString(); - const QString comment = index.model()->data( index, AgentTypeModel::DescriptionRole ).toString(); - - QFontMetrics fm = option.fontMetrics; - int hn = fm.boundingRect( 0, 0, 0, 0, Qt::AlignLeft, name ).height(); - int wn = fm.boundingRect( 0, 0, 0, 0, Qt::AlignLeft, name ).width(); - int hc = fm.boundingRect( 0, 0, 0, 0, Qt::AlignLeft, comment ).height(); - int wc = fm.boundingRect( 0, 0, 0, 0, Qt::AlignLeft, comment ).width(); - - int width = 0; - int height = 0; - - if ( !name.isEmpty() ) { - height += hn; - width = qMax( width, wn ); - } - - if ( !comment.isEmpty() ) { - height += hc; - width = qMax( width, wc ); - } - - height = qMax( height, 64 ) + 10; - width += 64 + 15; - - return QSize( width, height ); -} - -void AgentTypeWidgetDelegate::drawFocus( QPainter *painter, const QStyleOptionViewItem &option, const QRect &rect ) const -{ - if (option.state & QStyle::State_HasFocus) { - QStyleOptionFocusRect o; - o.QStyleOption::operator=(option); - o.rect = rect; - o.state |= QStyle::State_KeyboardFocusChange; - QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) - ? QPalette::Normal : QPalette::Disabled; - o.backgroundColor = option.palette.color(cg, (option.state & QStyle::State_Selected) - ? QPalette::Highlight : QPalette::Background); - QApplication::style()->drawPrimitive(QStyle::PE_FrameFocusRect, &o, painter); - } -} - -#include "agenttypewidget.moc" diff --git a/akonadi/agenttypewidget.h b/akonadi/agenttypewidget.h deleted file mode 100644 index 4cfe1f7c9..000000000 --- a/akonadi/agenttypewidget.h +++ /dev/null @@ -1,113 +0,0 @@ -/* - Copyright (c) 2006-2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_AGENTTYPEWIDGET_H -#define AKONADI_AGENTTYPEWIDGET_H - -#include "akonadi_export.h" - -#include - -namespace Akonadi { - -class AgentFilterProxyModel; -class AgentType; - -/** - * @short Provides a widget that lists all available agent types. - * - * The widget is listening on the dbus for changes, so the - * widget is updated automatically as soon as new agent types - * are added to or removed from the system. - * - * @code - * - * MyWidget::MyWidget( QWidget *parent ) - * : QWidget( parent ) - * { - * QVBoxLayout *layout = new QVBoxLayout( this ); - * - * mAgentTypeWidget = new Akonadi::AgentTypeWidget( this ); - * layout->addWidget( mAgentTypeWidget ); - * - * connect( mAgentTypeWidget, SIGNAL( currentChanged( Akonadi::AgentType&, Akonadi::AgentType& ) ), - * this, SLOT( slotTypeChanged( Akonadi::AgentType& ) ) ); - * } - * - * ... - * - * MyWidget::slotTypeChanged( Akonadi::AgentType ¤t, Akonadi::AgentType& ) - * { - * qDebug() << "New selected type:" << current.name(); - * } - * - * @endcode - * - * @author Tobias Koenig - */ -class AKONADI_EXPORT AgentTypeWidget : public QWidget -{ - Q_OBJECT - - public: - /** - * Creates a new agent type widget. - * - * @param parent The parent widget. - */ - explicit AgentTypeWidget( QWidget *parent = 0 ); - - /** - * Destroys the agent type widget. - */ - ~AgentTypeWidget(); - - /** - * Returns the current agent type or an invalid agent type - * if no agent type is selected. - */ - AgentType currentAgentType() const; - - /** - * Returns the agent filter proxy model, use this to filter by - * agent mimetype or capabilities. - */ - AgentFilterProxyModel* agentFilterProxyModel() const; - - Q_SIGNALS: - /** - * This signal is emitted whenever the current agent type changes. - * - * @param current The current agent type. - * @param previous The previous agent type. - */ - void currentChanged( const Akonadi::AgentType ¤t, const Akonadi::AgentType &previous ); - - private: - //@cond PRIVATE - class Private; - Private* const d; - - Q_PRIVATE_SLOT( d, void currentAgentTypeChanged( const QModelIndex&, const QModelIndex& ) ) - //@endcond -}; - -} - -#endif diff --git a/akonadi/akonadi_export.h b/akonadi/akonadi_export.h deleted file mode 100644 index f93eb0a12..000000000 --- a/akonadi/akonadi_export.h +++ /dev/null @@ -1,36 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2007 David Faure - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef AKONADI_EXPORT_H -#define AKONADI_EXPORT_H - -/* needed for KDE_EXPORT and KDE_IMPORT macros */ -#include - -#ifndef AKONADI_EXPORT -# if defined(MAKE_AKONADI_KDE_LIB) - /* We are building this library */ -# define AKONADI_EXPORT KDE_EXPORT -# else - /* We are using this library */ -# define AKONADI_EXPORT KDE_IMPORT -# endif -#endif - -#endif diff --git a/akonadi/akonadiprivate_export.h b/akonadi/akonadiprivate_export.h deleted file mode 100644 index 8e3e6b27b..000000000 --- a/akonadi/akonadiprivate_export.h +++ /dev/null @@ -1,40 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2007 David Faure - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef AKONADIPRIVATE_EXPORT_H -#define AKONADIPRIVATE_EXPORT_H - -/* needed for KDE_EXPORT and KDE_IMPORT macros */ -#include - -#ifdef COMPILING_TESTS -# ifndef AKONADI_TESTS_EXPORT -# if defined(MAKE_AKONADI_KDE_LIB) - /* We are building this library */ -# define AKONADI_TESTS_EXPORT KDE_EXPORT -# else - /* We are using this library */ -# define AKONADI_TESTS_EXPORT KDE_IMPORT -# endif -# endif -#else /* not compiling tests */ -# define AKONADI_TESTS_EXPORT -#endif - -#endif diff --git a/akonadi/attribute.cpp b/akonadi/attribute.cpp deleted file mode 100644 index 5107915fe..000000000 --- a/akonadi/attribute.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - Copyright (c) 2006 - 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "attribute.h" - -using namespace Akonadi; - -Attribute::~ Attribute( ) -{ -} - diff --git a/akonadi/attribute.h b/akonadi/attribute.h deleted file mode 100644 index 2b9a38202..000000000 --- a/akonadi/attribute.h +++ /dev/null @@ -1,171 +0,0 @@ -/* - Copyright (c) 2006 - 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_ATTRIBUTE_H -#define AKONADI_ATTRIBUTE_H - -#include "akonadi_export.h" - -#include - -namespace Akonadi { - -/** - * @short Provides interface for custom attributes for Entity. - * - * This class is an interface for custom attributes, that can be stored - * in an entity. Attributes should be meta data, e.g. ACLs, quotas etc. - * that are not part of the entities' data itself. - * - * To provide custom attributes, you have to subclass from this interface - * and reimplement the pure virtual methods. - * - * @code - * - * class SecrecyAttribute : public Akonadi::Attribute - * { - * public: - * enum Secrecy - * { - * Public, - * Private, - * Confidential - * }; - * - * SecrecyAttribute( Secrecy secrecy = Public ) - * : mSecrecy( secrecy ) - * { - * } - * - * void setSecrecy( Secrecy secrecy ) - * { - * mSecrecy = secrecy; - * } - * - * Secrecy secrecy() const - * { - * return mSecrecy; - * } - * - * virtual QByteArray type() const - * { - * return "secrecy"; - * } - * - * virtual Attribute* clone() const - * { - * return new SecrecyAttribute( mSecrecy ); - * } - * - * virtual QByteArray serialized() const - * { - * switch ( mSecrecy ) { - * case Public: return "public"; break; - * case Private: return "private"; break; - * case Confidential: return "confidential"; break; - * } - * } - * - * virtual void deserialize( const QByteArray &data ) - * { - * if ( data == "public" ) - * mSecrecy = Public; - * else if ( data == "private" ) - * mSecrecy = Private; - * else if ( data == "confidential" ) - * mSecrecy = Confidential; - * } - * } - * - * @endcode - * - * Additionally, you need to register your attribute with Akonadi::AttributeFactory - * for automatic deserialization during retrieving of collecitons or items: - * - * @code - * AttributeFactory::registerAttribute(); - * @endcode - * - * The custom attributes can be used in the following way: - * - * @code - * - * Akonadi::Item item( "text/directory" ); - * SecrecyAttribute* attr = item.attribute( Item::AddIfMissing ); - * attr.setSecrecy( SecrecyAttribute::Confidential ); - * - * @endcode - * - * and - * - * @code - * - * Akonadi::Item item = ... - * - * if ( item.hasAttribute() ) { - * SecrecyAttribute *attr = item.attribute(); - * - * SecrecyAttribute::Secrecy secrecy = attr->secrecy(); - * ... - * } - * @endcode - * - * @author Volker Krause - */ -class AKONADI_EXPORT Attribute -{ - public: - /** - * Describes a list of attributes. - */ - typedef QList List; - - /** - * Returns the type of the attribute. - */ - virtual QByteArray type() const = 0; - - /** - * Destroys this attribute. - */ - virtual ~Attribute(); - - /** - * Creates a copy of this attribute. - */ - virtual Attribute* clone() const = 0; - - /** - * Returns a QByteArray representation of the attribute which will be - * storaged. This can be raw binary data, no encoding needs to be applied. - */ - virtual QByteArray serialized() const = 0; - - /** - * Sets the data of this attribute, using the same encoding - * as returned by toByteArray(). - * - * @param data The encoded attribute data. - */ - virtual void deserialize( const QByteArray &data ) = 0; -}; - -} - -#endif diff --git a/akonadi/attributefactory.cpp b/akonadi/attributefactory.cpp deleted file mode 100644 index 66417c478..000000000 --- a/akonadi/attributefactory.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* - Copyright (c) 2007 - 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "attributefactory.h" - -#include "collectiondisplayattribute.h" -#include "collectionrightsattribute.h" - -#include - -#include - -using namespace Akonadi; - -/** - * @internal - */ -class DefaultAttribute : public Attribute -{ - public: - explicit DefaultAttribute( const QByteArray &type, const QByteArray &value = QByteArray() ) : - mType( type ), - mValue( value ) - {} - - QByteArray type() const { return mType; } - Attribute* clone() const - { - return new DefaultAttribute( mType, mValue ); - } - - QByteArray serialized() const { return mValue; } - void deserialize( const QByteArray &data ) { mValue = data; } - - private: - QByteArray mType, mValue; -}; - -/** - * @internal - */ -class AttributeFactory::Private -{ - public: - QHash attributes; -}; - -/** - * @internal - */ -class StaticAttributeFactory : public AttributeFactory -{ - public: - StaticAttributeFactory() : AttributeFactory(), initialized( false ) {} - void init() { - if ( initialized ) - return; - initialized = true; - - // Register built-in attributes - AttributeFactory::registerAttribute(); - AttributeFactory::registerAttribute(); - } - bool initialized; -}; - -K_GLOBAL_STATIC( StaticAttributeFactory, s_attributeInstance ) - - -AttributeFactory* AttributeFactory::self() -{ - s_attributeInstance->init(); - return s_attributeInstance; -} - -AttributeFactory::AttributeFactory() - : d( new Private ) -{ -} - -AttributeFactory::~ AttributeFactory() -{ - qDeleteAll( d->attributes ); - delete d; -} - -void AttributeFactory::registerAttribute(Attribute *attr) -{ - Q_ASSERT( !d->attributes.contains( attr->type() ) ); - d->attributes.insert( attr->type(), attr ); -} - -Attribute* AttributeFactory::createAttribute(const QByteArray &type) -{ - Attribute* attr = self()->d->attributes.value( type ); - if ( attr ) - return attr->clone(); - return new DefaultAttribute( type ); -} diff --git a/akonadi/attributefactory.h b/akonadi/attributefactory.h deleted file mode 100644 index 1b9229799..000000000 --- a/akonadi/attributefactory.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - Copyright (c) 2007 - 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_ATTRIBUTEFACTORY_H -#define AKONADI_ATTRIBUTEFACTORY_H - -#include - -namespace Akonadi { - -/** - * @short Provides the functionality of registering and creating arbitrary - * entity attributes. - * - * This class provides the functionality of registering and creating arbitrary Attributes for Entity - * and its subclasses (e.g. Item and Collection). - * - * @code - * - * // register the type first - * Akonadi::AttributeFactory::registerAttribute(); - * - * ... - * - * // use it anywhere else in the application - * SecrecyAttribute *attr = Akonadi::AttributeFactory::createAttribute( "secrecy" ); - * - * @endcode - * - * @author Volker Krause - */ -class AKONADI_EXPORT AttributeFactory -{ - public: - //@cond PRIVATE - ~AttributeFactory(); - //@endcond - - /** - * Register a custom attribute of type T. - */ - template inline static void registerAttribute() - { - AttributeFactory::self()->registerAttribute( new T ); - } - - /** - * Creates an entity attribute object of the given type. - * - * @param type The attribute type. - */ - static Attribute* createAttribute( const QByteArray &type ); - - protected: - //@cond PRIVATE - AttributeFactory(); - - private: - static AttributeFactory* self(); - void registerAttribute( Attribute *attribute ); - - class Private; - Private* const d; - //@endcond -}; - -} - -#endif diff --git a/akonadi/cachepolicy.cpp b/akonadi/cachepolicy.cpp deleted file mode 100644 index c96657cbf..000000000 --- a/akonadi/cachepolicy.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "cachepolicy.h" -#include "collection.h" - -using namespace Akonadi; - -/** - * @internal - */ -class CachePolicy::Private : public QSharedData -{ - public: - Private() : - QSharedData(), - inherit( true ), - timeout( -1 ), - interval( -1 ), - syncOnDemand( false ) - {} - - Private( const Private &other ) : - QSharedData( other ) - { - inherit = other.inherit; - localParts = other.localParts; - timeout = other.timeout; - interval = other.interval; - syncOnDemand = other.syncOnDemand; - } - - bool inherit; - QStringList localParts; - int timeout; - int interval; - bool syncOnDemand; -}; - - -CachePolicy::CachePolicy() : - d( new Private ) -{ -} - -CachePolicy::CachePolicy(const CachePolicy & other) : - d( other.d ) -{ -} - -CachePolicy::~ CachePolicy() -{ -} - -CachePolicy & CachePolicy::operator =(const CachePolicy & other) -{ - d = other.d; - return *this; -} - -bool Akonadi::CachePolicy::operator ==(const CachePolicy & other) const -{ - if ( !d->inherit && !other.d->inherit ) { - return d->localParts == other.d->localParts - && d->timeout == other.d->timeout - && d->interval == other.d->interval - && d->syncOnDemand == other.d->syncOnDemand; - } - return d->inherit == other.d->inherit; -} - -bool CachePolicy::inheritFromParent() const -{ - return d->inherit; -} - -void CachePolicy::setInheritFromParent(bool inherit) -{ - d->inherit = inherit; -} - -QStringList CachePolicy::localParts() const -{ - return d->localParts; -} - -void CachePolicy::setLocalParts(const QStringList & parts) -{ - d->localParts = parts; -} - -int CachePolicy::cacheTimeout() const -{ - return d->timeout; -} - -void CachePolicy::setCacheTimeout(int timeout) -{ - d->timeout = timeout; -} - -int CachePolicy::intervalCheckTime() const -{ - return d->interval; -} - -void CachePolicy::setIntervalCheckTime(int time) -{ - d->interval = time; -} - -bool CachePolicy::syncOnDemand() const -{ - return d->syncOnDemand; -} - -void CachePolicy::setSyncOnDemand(bool enable) -{ - d->syncOnDemand = enable; -} diff --git a/akonadi/cachepolicy.h b/akonadi/cachepolicy.h deleted file mode 100644 index 3ed3e7ab9..000000000 --- a/akonadi/cachepolicy.h +++ /dev/null @@ -1,153 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_CACHEPOLICY_H -#define AKONADI_CACHEPOLICY_H - -#include "akonadi_export.h" - -#include -#include - -namespace Akonadi { - -/** - * @short Represents the caching policy for a collection. - * - * There is one cache policy per collection, it can either define to - * inherit all properties of the policy of the parent collection (the default) - * or specify the following values: - * - * - The item parts that should be permanently kept locally and are downloaded - * during a collection sync (eg. full mail vs. just the headers). - * - A time up to which non-permantly cached item parts have to be kept at - * least (0 - infinity). - * - Whether or not a collection sync is triggered on demand, ie. as soon - * as it is accessed by a client. - * - An optional time interval for regular collection sync (aka interval - * mail check). - * - * @code - * - * Akonadi::CachePolicy policy; - * policy.setCacheTimeout( 30 ); - * policy.setIntervalCheckTime( 20 ); - * - * Akonadi::Collection collection = ... - * collection.setCachePolicy( policy ); - * - * @endcode - * - * @todo Do we also need a size limit for the cache as well? - * @todo on a POP3 account, is should not be possible to change locally cached parts, find a solution for that - * - * @author Volker Krause - */ -class AKONADI_EXPORT CachePolicy -{ - public: - /** - * Creates an empty cache policy. - */ - CachePolicy(); - - /** - * Creates a cache policy from an @p other cache policy. - */ - CachePolicy( const CachePolicy &other ); - - /** - * Destroys the cache policy. - */ - ~CachePolicy(); - - /** - * Returns whether it inherits cache policy from parent collection. - */ - bool inheritFromParent() const; - - /** - * Sets whether the cache policy should be inherited from the parent collection. - */ - void setInheritFromParent( bool inherit ); - - /** - * Returns the parts to permanently cache locally. - */ - QStringList localParts() const; - - /** - * Specifies the parts to permanently cache locally. - */ - void setLocalParts( const QStringList &parts ); - - /** - * Returns the cache timeout for non-permanently cached parts in minutes, - * -1 means indefinitely. - */ - int cacheTimeout() const; - - /** - * Sets cache timeout for non-permanently cached parts. - * @param timeout Timeout in minutes, -1 for indefinitely. - */ - void setCacheTimeout( int timeout ); - - /** - * Returns the interval check time in minutes, -1 for never. - */ - int intervalCheckTime() const; - - /** - * Sets interval check time. - * @param time Check time interval in minutes, -1 for never. - */ - void setIntervalCheckTime( int time ); - - /** - * Returns whether the collection shall be synced automatically when necessary. - */ - bool syncOnDemand() const; - - /** - * Sets whether the collection shall be synced automatically when necessary. - * @param enable If @c true the collection is synced. - */ - void setSyncOnDemand( bool enable ); - - /** - * @internal. - */ - CachePolicy& operator=( const CachePolicy &other ); - - /** - * @internal - */ - bool operator==( const CachePolicy &other ) const; - - private: - //@cond PRIVATE - class Private; - QSharedDataPointer d; - //@endcond -}; - -} - -#endif diff --git a/akonadi/cachepolicypage.cpp b/akonadi/cachepolicypage.cpp deleted file mode 100644 index 02fc93320..000000000 --- a/akonadi/cachepolicypage.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "cachepolicypage.h" - -#include "cachepolicy.h" -#include "collection.h" -#include "collectionutils_p.h" - -using namespace Akonadi; - -CachePolicyPage::CachePolicyPage(QWidget * parent) : - CollectionPropertiesPage( parent ) -{ - setPageTitle( i18n( "Cache" ) ); - ui.setupUi( this ); - connect( ui.checkInterval, SIGNAL( valueChanged( int ) ), - SLOT( slotIntervalValueChanged( int ) ) ); - connect( ui.localCacheTimeout, SIGNAL( valueChanged( int ) ), - SLOT( slotCacheValueChanged( int ) ) ); -} - -bool Akonadi::CachePolicyPage::canHandle(const Collection & collection) const -{ - return !CollectionUtils::isVirtual( collection ); -} - -void CachePolicyPage::load(const Collection & collection) -{ - CachePolicy policy = collection.cachePolicy(); - - int interval = policy.intervalCheckTime(); - if (interval == -1) - interval = 0; - - int cache = policy.cacheTimeout(); - if (cache == -1) - cache = 0; - - ui.inherit->setChecked( policy.inheritFromParent() ); - ui.checkInterval->setValue( interval ); - ui.localCacheTimeout->setValue( cache ); - ui.syncOnDemand->setChecked( policy.syncOnDemand() ); - ui.localParts->setItems( policy.localParts() ); -} - -void CachePolicyPage::save(Collection & collection) -{ - int interval = ui.checkInterval->value(); - if (interval == 0) - interval = -1; - - int cache = ui.localCacheTimeout->value(); - if (cache == 0) - cache = -1; - - CachePolicy policy = collection.cachePolicy(); - policy.setInheritFromParent( ui.inherit->isChecked() ); - policy.setIntervalCheckTime( interval ); - policy.setCacheTimeout( cache ); - policy.setSyncOnDemand( ui.syncOnDemand->isChecked() ); - policy.setLocalParts( ui.localParts->items() ); - collection.setCachePolicy( policy ); -} - -void CachePolicyPage::slotIntervalValueChanged( int i ) -{ - ui.checkInterval->setSuffix( ' ' + i18np( "minute", "minutes", i ) ); -} - -void CachePolicyPage::slotCacheValueChanged( int i ) -{ - ui.localCacheTimeout->setSuffix( ' ' + i18np( "minute", "minutes", i ) ); -} - -#include "cachepolicypage.moc" diff --git a/akonadi/cachepolicypage.h b/akonadi/cachepolicypage.h deleted file mode 100644 index 82568db3a..000000000 --- a/akonadi/cachepolicypage.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_CACHEPOLICYPAGE_H -#define AKONADI_CACHEPOLICYPAGE_H - -#include - -#include "ui_cachepolicypage.h" - -namespace Akonadi { - -/** - @internal - - Cache policy configuration page. -*/ -class CachePolicyPage : public CollectionPropertiesPage -{ - Q_OBJECT - public: - explicit CachePolicyPage( QWidget * parent ); - - bool canHandle( const Collection &collection ) const; - void load( const Collection &collection ); - void save( Collection &collection ); - - private: - Ui::CachePolicyPage ui; - - private slots: - void slotIntervalValueChanged( int ); - void slotCacheValueChanged( int ); -}; - -AKONADI_COLLECTION_PROPERTIES_PAGE_FACTORY(CachePolicyPageFactory, CachePolicyPage) - -} - -#endif diff --git a/akonadi/cachepolicypage.ui b/akonadi/cachepolicypage.ui deleted file mode 100644 index 245dbcc7f..000000000 --- a/akonadi/cachepolicypage.ui +++ /dev/null @@ -1,156 +0,0 @@ - - CachePolicyPage - - - true - - - - 0 - 0 - 602 - 461 - - - - - - - Inherit cache policy from parent - - - true - - - false - - - - - - - false - - - Cache Policy - - - - - - Interval check time: - - - - - - - -1 - - - 0 - - - minutes - - - Never - - - - - - - Local cache timeout: - - - - - - - -1 - - - 0 - - - minutes - - - Never - - - - - - - Synchronize on demand - - - - - - - - - - false - - - Locally Cached Parts - - - KEditListBox::Add|KEditListBox::Remove - - - - - - - - KEditListBox - QGroupBox -
keditlistbox.h
-
- - KIntNumInput - QWidget -
knuminput.h
-
-
- - - - inherit - toggled(bool) - groupBox - setDisabled(bool) - - - 65 - 20 - - - 71 - 39 - - - - - inherit - toggled(bool) - localParts - setDisabled(bool) - - - 199 - 14 - - - 321 - 192 - - - - -
diff --git a/akonadi/changerecorder.cpp b/akonadi/changerecorder.cpp deleted file mode 100644 index 97330cb91..000000000 --- a/akonadi/changerecorder.cpp +++ /dev/null @@ -1,184 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "changerecorder.h" -#include "monitor_p.h" - -#include -#include - -using namespace Akonadi; - -class Akonadi::ChangeRecorderPrivate : public MonitorPrivate -{ - public: - ChangeRecorderPrivate( ChangeRecorder* parent ) : - MonitorPrivate( parent ), - settings( 0 ), - enableChangeRecording( true ) - { - } - - Q_DECLARE_PUBLIC( ChangeRecorder ) - NotificationMessage::List pendingNotifications; - QSettings *settings; - bool enableChangeRecording; - - virtual void slotNotify( const NotificationMessage::List &msgs ) - { - if ( !enableChangeRecording ) { - foreach( const NotificationMessage &msg, msgs ) - processNotification( msg ); - return; - } - - Q_Q( ChangeRecorder ); - int oldChanges = pendingNotifications.count(); - foreach ( const NotificationMessage &msg, msgs ) { - if ( acceptNotification( msg ) ) - NotificationMessage::appendAndCompress( pendingNotifications, msg ); - } - if ( pendingNotifications.count() != oldChanges ) { - saveNotifications(); - emit q->changesAdded(); - } - } - - void loadNotifications() - { - pendingNotifications.clear(); - QStringList list; - settings->beginGroup( QLatin1String( "ChangeRecorder" ) ); - int size = settings->beginReadArray( QLatin1String( "change" ) ); - for ( int i = 0; i < size; ++i ) { - settings->setArrayIndex( i ); - NotificationMessage msg; - msg.setSessionId( settings->value( QLatin1String( "sessionId" ) ).toByteArray() ); - msg.setType( (NotificationMessage::Type)settings->value( QLatin1String( "type" ) ).toInt() ); - msg.setOperation( (NotificationMessage::Operation)settings->value( QLatin1String( "op" ) ).toInt() ); - msg.setUid( settings->value( QLatin1String( "uid" ) ).toLongLong() ); - msg.setRemoteId( settings->value( QLatin1String( "rid" ) ).toString() ); - msg.setResource( settings->value( QLatin1String( "resource" ) ).toByteArray() ); - msg.setParentCollection( settings->value( QLatin1String( "parentCol" ) ).toLongLong() ); - msg.setParentDestCollection( settings->value( QLatin1String( "parentDestCol" ) ).toLongLong() ); - msg.setMimeType( settings->value( QLatin1String( "mimeType" ) ).toString() ); - list = settings->value( QLatin1String( "itemParts" ) ).toStringList(); - QSet itemParts; - Q_FOREACH( const QString &entry, list ) - itemParts.insert( entry.toLatin1() ); - msg.setItemParts( itemParts ); - pendingNotifications << msg; - } - settings->endArray(); - settings->endGroup(); - } - - void saveNotifications() - { - if ( !settings ) - return; - settings->beginGroup( QLatin1String( "ChangeRecorder" ) ); - settings->beginWriteArray( QLatin1String( "change" ), pendingNotifications.count() ); - for ( int i = 0; i < pendingNotifications.count(); ++i ) { - settings->setArrayIndex( i ); - NotificationMessage msg = pendingNotifications.at( i ); - settings->setValue( QLatin1String( "sessionId" ), msg.sessionId() ); - settings->setValue( QLatin1String( "type" ), msg.type() ); - settings->setValue( QLatin1String( "op" ), msg.operation() ); - settings->setValue( QLatin1String( "uid" ), msg.uid() ); - settings->setValue( QLatin1String( "rid" ), msg.remoteId() ); - settings->setValue( QLatin1String( "resource" ), msg.resource() ); - settings->setValue( QLatin1String( "parentCol" ), msg.parentCollection() ); - settings->setValue( QLatin1String( "parentDestCol" ), msg.parentDestCollection() ); - settings->setValue( QLatin1String( "mimeType" ), msg.mimeType() ); - - QStringList list; - const QSet itemParts = msg.itemParts(); - QSetIterator it( itemParts ); - while ( it.hasNext() ) - list.append( QString::fromLatin1( it.next() ) ); - - settings->setValue( QLatin1String( "itemParts" ), list ); - } - settings->endArray(); - settings->endGroup(); - } - -}; - -ChangeRecorder::ChangeRecorder(QObject * parent) : - Monitor( new ChangeRecorderPrivate( this ), parent ) -{ - Q_D( ChangeRecorder ); - d->connectToNotificationManager(); -} - -ChangeRecorder::~ ChangeRecorder() -{ - Q_D( ChangeRecorder ); - d->saveNotifications(); -} - -void ChangeRecorder::setConfig(QSettings * settings) -{ - Q_D( ChangeRecorder ); - if ( settings ) { - d->settings = settings; - Q_ASSERT( d->pendingNotifications.isEmpty() ); - d->loadNotifications(); - } else if ( d->settings ) { - d->saveNotifications(); - d->settings = settings; - } -} - -void ChangeRecorder::replayNext() -{ - Q_D( ChangeRecorder ); - while( !d->pendingNotifications.isEmpty() ) { - const NotificationMessage msg = d->pendingNotifications.first(); - if ( d->processNotification( msg ) ) - break; - d->pendingNotifications.takeFirst(); - } - d->saveNotifications(); -} - -bool ChangeRecorder::isEmpty() const -{ - Q_D( const ChangeRecorder ); - return d->pendingNotifications.isEmpty(); -} - -void ChangeRecorder::changeProcessed() -{ - Q_D( ChangeRecorder ); - if ( !d->pendingNotifications.isEmpty() ) - d->pendingNotifications.removeFirst(); - d->saveNotifications(); -} - -void ChangeRecorder::setChangeRecordingEnabled( bool enable ) -{ - Q_D( ChangeRecorder ); - d->enableChangeRecording = enable; - Q_ASSERT( enable || d->pendingNotifications.isEmpty() ); -} - -#include "changerecorder.moc" diff --git a/akonadi/changerecorder.h b/akonadi/changerecorder.h deleted file mode 100644 index 46d3d61b0..000000000 --- a/akonadi/changerecorder.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_CHANGERECORDER_H -#define AKONADI_CHANGERECORDER_H - -#include - -class QSettings; - -namespace Akonadi { - -class ChangeRecorderPrivate; - -/** - * @short Records and replays change notification. - * - * This class is responsible for recording change notification during - * an agent is not online and replay the notifications when the agent - * is online again. Therefor the agent doesn't have to care about - * online/offline mode in its synchronization algorithm. - * - * @author Volker Krause - */ -class AKONADI_EXPORT ChangeRecorder : public Monitor -{ - Q_OBJECT - public: - /** - * Creates a new change recorder. - */ - explicit ChangeRecorder( QObject *parent = 0 ); - - /** - * Destroys the change recorder. - * All not yet processed changes are written back to the config file. - */ - ~ChangeRecorder(); - - /** - * Sets the QSettings object used for persisting recorded changes. - */ - void setConfig( QSettings *settings ); - - /** - * Returns whether there are recorded changes. - */ - bool isEmpty() const; - - /** - * Removes the previously emitted change from the records. - */ - void changeProcessed(); - - /** - * Enables change recording. If change recording is disabled, this class - * behaves exactly like Akonadi::Monitor. - * Change recording is enabled by default. - */ - void setChangeRecordingEnabled( bool enable ); - - public Q_SLOTS: - /** - * Replay the next change notification and erase the previous one from the record. - */ - void replayNext(); - - Q_SIGNALS: - /** - * Emitted when new changes are recorded. - */ - void changesAdded(); - - private: - Q_DECLARE_PRIVATE( ChangeRecorder ) -}; - -} - -#endif diff --git a/akonadi/collection.cpp b/akonadi/collection.cpp deleted file mode 100644 index 3a477c728..000000000 --- a/akonadi/collection.cpp +++ /dev/null @@ -1,214 +0,0 @@ -/* - Copyright (c) 2006 - 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "collection.h" -#include "collection_p.h" - -#include "attributefactory.h" -#include "cachepolicy.h" -#include "collectionrightsattribute.h" -#include "collectionstatistics.h" -#include "entity_p.h" - -#include -#include -#include -#include - -#include -#include - -using namespace Akonadi; - -class CollectionRoot : public Collection -{ - public: - CollectionRoot() : Collection( 0 ) { - QStringList types; - types << Collection::mimeType(); - setContentMimeTypes( types ); - } -}; - -K_GLOBAL_STATIC( CollectionRoot, s_root ) - -Collection::Collection() : - Entity( new CollectionPrivate ) -{ - Q_D( Collection ); - static int lastId = -1; - d->mId = lastId--; -} - -Collection::Collection( Id id ) : - Entity( new CollectionPrivate( id ) ) -{ -} - -Collection::Collection(const Collection & other) : - Entity( other ) -{ -} - -Collection::~Collection() -{ -} - -QString Collection::name( ) const -{ - return d_func()->name; -} - -void Collection::setName( const QString & name ) -{ - Q_D( Collection ); - d->name = name; -} - -Collection::Rights Collection::rights() const -{ - CollectionRightsAttribute *attr = attribute(); - if ( attr ) - return attr->rights(); - else - return AllRights; -} - -void Collection::setRights( Rights rights ) -{ - CollectionRightsAttribute *attr = attribute( AddIfMissing ); - attr->setRights( rights ); -} - -QStringList Collection::contentMimeTypes() const -{ - return d_func()->contentTypes; -} - -void Collection::setContentMimeTypes( const QStringList & types ) -{ - Q_D( Collection ); - d->contentTypes = types; - d->contentTypesChanged = true; -} - -Collection::Id Collection::parent() const -{ - return d_func()->parentId; -} - -void Collection::setParent( Id parent ) -{ - Q_D( Collection ); - d->parentId = parent; -} - -void Collection::setParent(const Collection & collection) -{ - Q_D( Collection ); - d->parentId = collection.id(); - d->parentRemoteId = collection.remoteId(); -} - -QString Collection::parentRemoteId() const -{ - return d_func()->parentRemoteId; -} - -void Collection::setParentRemoteId(const QString & remoteParent) -{ - Q_D( Collection ); - d->parentRemoteId = remoteParent; -} - -KUrl Collection::url() const -{ - KUrl url; - url.setProtocol( QString::fromLatin1("akonadi") ); - url.addQueryItem( QLatin1String("collection"), QString::number( id() ) ); - return url; -} - -Collection Collection::fromUrl( const KUrl &url ) -{ - if ( url.protocol() != QLatin1String( "akonadi" ) ) - return Collection(); - - const QString colStr = url.queryItem( QLatin1String( "collection" ) ); - bool ok = false; - Collection::Id colId = colStr.toLongLong( &ok ); - if ( !ok ) - return Collection(); - - if ( colId == 0 ) - return Collection::root(); - - return Collection( colId ); -} - -Collection Collection::root() -{ - return *s_root; -} - -QString Collection::mimeType( ) -{ - return QString::fromLatin1("inode/directory"); -} - -QString Collection::resource() const -{ - return d_func()->resource; -} - -void Collection::setResource(const QString & resource) -{ - Q_D( Collection ); - d->resource = resource; -} - -uint qHash( const Akonadi::Collection &collection ) -{ - return qHash( collection.id() ); -} - -CollectionStatistics Collection::statistics() const -{ - return d_func()->statistics; -} - -void Collection::setStatistics(const CollectionStatistics & statistics) -{ - Q_D( Collection ); - d->statistics = statistics; -} - -CachePolicy Collection::cachePolicy() const -{ - return d_func()->cachePolicy; -} - -void Collection::setCachePolicy(const CachePolicy & cachePolicy) -{ - Q_D( Collection ); - d->cachePolicy = cachePolicy; - d->cachePolicyChanged = true; -} - -AKONADI_DEFINE_PRIVATE( Akonadi::Collection ) diff --git a/akonadi/collection.h b/akonadi/collection.h deleted file mode 100644 index 211dccbce..000000000 --- a/akonadi/collection.h +++ /dev/null @@ -1,234 +0,0 @@ -/* - Copyright (c) 2006 - 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_COLLECTION_H -#define AKONADI_COLLECTION_H - -#include "akonadi_export.h" - -#include - -#include -#include - -class KUrl; - -namespace Akonadi { - -class CachePolicy; -class CollectionPrivate; -class CollectionStatistics; - -/** - * @short Represents a collection of PIM items. - * - * This class represents a collection of PIM items, such as a folder on a mail- or - * groupware-server. - * - * Collections are hierarchical, i.e., they may have a parent collection. - * - * @code - * - * using namespace Akonadi; - * - * // fetching all collections recursive, starting at the root collection - * CollectionFetchJob *job = new CollectionFetchJob( Collection::root(), CollectionFetchJob::Recursive ); - * if ( job->exec() ) { - * Collection::List collections = job->collections(); - * foreach( const Collection &collection, collections ) { - * qDebug() << "Name:" << collection.name(); - * } - * } - * - * @endcode - * - * @author Volker Krause - * - * @see \ref akonadi_concepts_collections "Akonadi Collection Concept" - */ -class AKONADI_EXPORT Collection : public Entity -{ - public: - /** - * Describes a list of collections. - */ - typedef QList List; - - /** - * Describes rights of a collection. - */ - enum Right { - ReadOnly = 0x0, ///< Can only read items or subcollection of this collection - CanChangeItem = 0x1, ///< Can change items in this collection - CanCreateItem = 0x2, ///< Can create new items in this collection - CanDeleteItem = 0x4, ///< Can delete items in this collection - CanChangeCollection = 0x8, ///< Can change subcollections in this collection - CanCreateCollection = 0x10, ///< Can create new subcollections in this collection - CanDeleteCollection = 0x20, ///< Can delete subcollections in this collection - AllRights = (CanChangeItem | CanCreateItem | CanDeleteItem | - CanChangeCollection | CanCreateCollection | CanDeleteCollection) ///< Has all rights on this collection - }; - Q_DECLARE_FLAGS(Rights, Right) - - /** - * Creates an invalid collection. - */ - Collection(); - - /** - * Create a new collection. - * - * @param id The unique identifier of the collection. - */ - explicit Collection( Id id ); - - /** - * Destroys the collection. - */ - ~Collection(); - - /** - * Creates a collection from an @p other collection. - */ - Collection( const Collection &other ); - - /** - * Creates a collection from the given @p url. - */ - static Collection fromUrl( const KUrl &url ); - - /** - * Returns the i18n'ed name of the collection. - */ - QString name() const; - - /** - * Sets the i18n'ed name of the collection. - * - * @param name The new collection name. - */ - void setName( const QString &name ); - - /** - * Returns the rights the user has on the collection. - */ - Rights rights() const; - - /** - * Sets the @p rights the user has on the collection. - */ - void setRights( Rights rights ); - - /** - * Returns a list of possible content mimetypes, - * e.g. message/rfc822, x-akonadi/collection for a mail folder that - * supports sub-folders. - */ - QStringList contentMimeTypes() const; - - /** - * Sets the list of possible content mime @p types. - */ - void setContentMimeTypes( const QStringList &types ); - - /** - * Returns the identifier of the parent collection. - */ - Id parent() const; - - /** - * Sets the identifier of the @p parent collection. - */ - void setParent( Id parent ); - - /** - * Sets the parent @p collection. - */ - void setParent( const Collection &collection ); - - /** - * Returns the parent remote identifier. - * @note This usually returns nothing for collections retrieved from the backend. - */ - QString parentRemoteId() const; - - /** - * Sets the parent's remote @p identifier. - */ - void setParentRemoteId( const QString &identifier ); - - /** - * Returns the root collection. - */ - static Collection root(); - - /** - * Returns the mimetype used for collections. - */ - static QString mimeType(); - - /** - * Returns the identifier of the resource owning the collection. - */ - QString resource() const; - - /** - * Sets the @p identifier of the resource owning the collection. - */ - void setResource( const QString &identifier ); - - /** - * Returns the cache policy of the collection. - */ - CachePolicy cachePolicy() const; - - /** - * Sets the cache @p policy of the collection. - */ - void setCachePolicy( const CachePolicy &policy ); - - /** - * Returns the collection statistics of the collection. - */ - CollectionStatistics statistics() const; - - /** - * Sets the collection @p statistics for the collection. - */ - void setStatistics( const CollectionStatistics &statistics ); - - /** - * Returns the collection url - */ - KUrl url() const; - - private: - AKONADI_DECLARE_PRIVATE( Collection ) - friend class CollectionFetchJob; - friend class CollectionModifyJob; -}; - -} - -AKONADI_EXPORT uint qHash( const Akonadi::Collection &collection ); - -Q_DECLARE_METATYPE(Akonadi::Collection) -Q_DECLARE_METATYPE(Akonadi::Collection::List) - -#endif diff --git a/akonadi/collection_p.h b/akonadi/collection_p.h deleted file mode 100644 index a9255aaa2..000000000 --- a/akonadi/collection_p.h +++ /dev/null @@ -1,96 +0,0 @@ -/* - Copyright (c) 2006 - 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_COLLECTION_P_H -#define AKONADI_COLLECTION_P_H - -#include "collection.h" -#include "cachepolicy.h" -#include "collectionstatistics.h" -#include "entity_p.h" - -#include "qstringlist.h" - -using namespace Akonadi; - -/** - * @internal - */ -class Akonadi::CollectionPrivate : public EntityPrivate -{ - public: - CollectionPrivate( Collection::Id id = -1 ) : - EntityPrivate( id ), - parentId( -1 ), - contentTypesChanged( false ), - cachePolicyChanged( false ) - {} - - CollectionPrivate( const CollectionPrivate &other ) : - EntityPrivate( other ) - { - parentId = other.parentId; - name = other.name; - parentRemoteId = other.parentRemoteId; - resource = other.resource; - statistics = other.statistics; - contentTypes = other.contentTypes; - cachePolicy = other.cachePolicy; - contentTypesChanged = other.contentTypesChanged; - cachePolicyChanged = other.cachePolicyChanged; - } - - ~CollectionPrivate() - { - } - - CollectionPrivate* clone() const - { - return new CollectionPrivate( *this ); - } - - void resetChangeLog() - { - contentTypesChanged = false; - cachePolicyChanged = false; - EntityPrivate::resetChangeLog(); - } - - static Collection newRoot() - { - Collection root( 0 ); - QStringList types; - types << Collection::mimeType(); - root.setContentMimeTypes( types ); - return root; - } - - Collection::Id parentId; - QString name; - QString parentRemoteId; - QString resource; - CollectionStatistics statistics; - QStringList contentTypes; - static const Collection root; - CachePolicy cachePolicy; - bool contentTypesChanged; - bool cachePolicyChanged; -}; - -#endif diff --git a/akonadi/collectioncopyjob.cpp b/akonadi/collectioncopyjob.cpp deleted file mode 100644 index 32020748f..000000000 --- a/akonadi/collectioncopyjob.cpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "collectioncopyjob.h" - -#include "collection.h" -#include "job_p.h" - -using namespace Akonadi; - -class Akonadi::CollectionCopyJobPrivate : public JobPrivate -{ - public: - CollectionCopyJobPrivate( CollectionCopyJob *parent ) - : JobPrivate( parent ) - { - } - - Collection mSource; - Collection mTarget; -}; - -CollectionCopyJob::CollectionCopyJob(const Collection & source, const Collection & target, QObject * parent) - : Job( new CollectionCopyJobPrivate( this ), parent ) -{ - Q_D( CollectionCopyJob ); - - d->mSource = source; - d->mTarget = target; -} - -CollectionCopyJob::~CollectionCopyJob() -{ -} - -void CollectionCopyJob::doStart() -{ - Q_D( CollectionCopyJob ); - - QByteArray command = d->newTag(); - command += " COLCOPY "; - command += QByteArray::number( d->mSource.id() ); - command += ' '; - command += QByteArray::number( d->mTarget.id() ); - command += '\n'; - d->writeData( command ); -} - -#include "collectioncopyjob.moc" diff --git a/akonadi/collectioncopyjob.h b/akonadi/collectioncopyjob.h deleted file mode 100644 index 9b66fec14..000000000 --- a/akonadi/collectioncopyjob.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_COLLECTIONCOPYJOB_H -#define AKONADI_COLLECTIONCOPYJOB_H - -#include - -namespace Akonadi { - -class Collection; -class CollectionCopyJobPrivate; - -/** - * @short Job that copies a collection into another collection in the Akonadi storage. - * - * This job copies a single collection into a specified target collection. - * - * @code - * - * Akonadi::Collection source = ... - * Akonadi::Collection target = ... - * - * Akonadi::CollectionCopyJob *job = new Akonadi::CollectionCopyJob( source, target ); - * - * if ( job->exec() ) - * qDebug() << "Copied successfully"; - * else - * qDebug() << "Error occurred"; - * - * @endcode - * - * @author Volker Krause - */ -class AKONADI_EXPORT CollectionCopyJob : public Job -{ - Q_OBJECT - - public: - /** - * Creates a new collection copy job to copy the given @p source collection into @p target. - * - * @param source The collection to copy. - * @param target The target collection. - * @param parent The parent object. - */ - CollectionCopyJob( const Collection &source, const Collection &target, QObject *parent = 0 ); - - /** - * Destroys the collection copy job. - */ - ~CollectionCopyJob(); - - protected: - void doStart(); - - private: - Q_DECLARE_PRIVATE( CollectionCopyJob ) -}; - -} - -#endif diff --git a/akonadi/collectioncreatejob.cpp b/akonadi/collectioncreatejob.cpp deleted file mode 100644 index adb8eecbf..000000000 --- a/akonadi/collectioncreatejob.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "collectioncreatejob.h" -#include "imapparser_p.h" -#include "protocolhelper.h" - -#include "job_p.h" - -#include - -using namespace Akonadi; - -class Akonadi::CollectionCreateJobPrivate : public JobPrivate -{ - public: - CollectionCreateJobPrivate( CollectionCreateJob *parent ) - : JobPrivate( parent ) - { - } - - Collection mCollection; -}; - -CollectionCreateJob::CollectionCreateJob( const Collection &collection, QObject * parent ) - : Job( new CollectionCreateJobPrivate( this ), parent ) -{ - Q_D( CollectionCreateJob ); - - d->mCollection = collection; -} - -CollectionCreateJob::~CollectionCreateJob( ) -{ -} - -void CollectionCreateJob::doStart( ) -{ - Q_D( CollectionCreateJob ); - - QByteArray command = d->newTag() + " CREATE \"" + d->mCollection.name().toUtf8() + "\" "; - command += QByteArray::number( d->mCollection.parent() ); - command += " ("; - if ( !d->mCollection.contentMimeTypes().isEmpty() ) - { - QList cList; - foreach( const QString &s, d->mCollection.contentMimeTypes() ) cList << s.toLatin1(); - command += "MIMETYPE (" + ImapParser::join( cList, QByteArray(" ") ) + ')'; - } - command += " REMOTEID \"" + d->mCollection.remoteId().toUtf8() + '"'; - foreach ( Attribute* attr, d->mCollection.attributes() ) - command += ' ' + attr->type() + ' ' + ImapParser::quote( attr->serialized() ); - command += ' ' + ProtocolHelper::cachePolicyToByteArray( d->mCollection.cachePolicy() ); - command += ")\n"; - d->writeData( command ); - emitWriteFinished(); -} - -Collection CollectionCreateJob::collection() const -{ - Q_D( const CollectionCreateJob ); - - return d->mCollection; -} - -void CollectionCreateJob::doHandleResponse(const QByteArray & tag, const QByteArray & data) -{ - Q_D( CollectionCreateJob ); - - if ( tag == "*" ) { - Collection col; - ProtocolHelper::parseCollection( data, col ); - if ( !col.isValid() ) - return; - - col.setParent( d->mCollection.parent() ); - col.setName( d->mCollection.name() ); - col.setRemoteId( d->mCollection.remoteId() ); - d->mCollection = col; - } else { - Job::doHandleResponse( tag, data ); - } -} - -#include "collectioncreatejob.moc" diff --git a/akonadi/collectioncreatejob.h b/akonadi/collectioncreatejob.h deleted file mode 100644 index 503b7d52a..000000000 --- a/akonadi/collectioncreatejob.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_COLLECTIONCREATEJOB_H -#define AKONADI_COLLECTIONCREATEJOB_H - -#include - -namespace Akonadi { - -class Collection; -class CollectionCreateJobPrivate; - -/** - * @short Job that creates a new collection in the Akonadi storage. - * - * This job creates a new collection with all the set properties. - * You have to use setParentCollection() to define the collection, the - * new collection shall be located in. - * - * @code - * - * // create a new top-level collection - * Akonadi::Collection collection; - * collection.setParent( Collection::root() ); - * collection.setName( "Events" ); - * collection.setContentMimeTypes( QStringList( "text/calendar" ) ); - * - * Akonadi::CollectionCreateJob *job = new Akonadi::CollectionCreateJob( collection ); - * if ( job->exec() ) - * qDebug() << "Created successfully"; - * else - * qDebug() << "Error occurred"; - * - * @endcode - * - * @author Volker Krause - */ -class AKONADI_EXPORT CollectionCreateJob : public Job -{ - Q_OBJECT - public: - /** - * Creates a new collection create job. - * - * @param collection The new collection. - * @param parent The parent object. - */ - explicit CollectionCreateJob( const Collection &collection, QObject *parent = 0 ); - - /** - * Destroys the collection create job. - */ - virtual ~CollectionCreateJob(); - - /** - * Returns the created collection if the job was executed succesfull. - */ - Collection collection() const; - - protected: - virtual void doStart(); - virtual void doHandleResponse( const QByteArray &tag, const QByteArray &data ); - - private: - Q_DECLARE_PRIVATE( CollectionCreateJob ) -}; - -} - -#endif diff --git a/akonadi/collectiondeletejob.cpp b/akonadi/collectiondeletejob.cpp deleted file mode 100644 index 0690b9aba..000000000 --- a/akonadi/collectiondeletejob.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "collectiondeletejob.h" - -#include "collection.h" -#include "job_p.h" - -using namespace Akonadi; - -class Akonadi::CollectionDeleteJobPrivate : public JobPrivate -{ - public: - CollectionDeleteJobPrivate( CollectionDeleteJob *parent ) - : JobPrivate( parent ) - { - } - - Collection mCollection; -}; - -CollectionDeleteJob::CollectionDeleteJob(const Collection &collection, QObject * parent) - : Job( new CollectionDeleteJobPrivate( this ), parent ) -{ - Q_D( CollectionDeleteJob ); - - d->mCollection = collection; -} - -CollectionDeleteJob::~CollectionDeleteJob() -{ -} - -void CollectionDeleteJob::doStart() -{ - Q_D( CollectionDeleteJob ); - - d->writeData( d->newTag() + " DELETE " + QByteArray::number( d->mCollection.id() ) + '\n' ); -} - -#include "collectiondeletejob.moc" diff --git a/akonadi/collectiondeletejob.h b/akonadi/collectiondeletejob.h deleted file mode 100644 index 01a6c32cd..000000000 --- a/akonadi/collectiondeletejob.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_COLLECTIONDELETEJOB_H -#define AKONADI_COLLECTIONDELETEJOB_H - -#include - -namespace Akonadi { - -class Collection; -class CollectionDeleteJobPrivate; - -/** - * @short Job that deletes a collection in the Akonadi storage. - * - * This job deletes a collection and all its sub-collections as well as all associated content. - * - * @code - * - * Akonadi::Collection collection = ... - * - * Akonadi::CollectionDeleteJob *job = new Akonadi::CollectionDeleteJob( collection ); - * - * if ( job->exec() ) - * qDebug() << "Deleted successfully"; - * else - * qDebug() << "Error occurred"; - * - * @endcode - * - * @author Volker Krause - */ -class AKONADI_EXPORT CollectionDeleteJob : public Job -{ - Q_OBJECT - - public: - /** - * Creates a new collection delete job. - * - * @param collection The collection to delete. - * @param parent The parent object. - */ - explicit CollectionDeleteJob( const Collection &collection, QObject *parent = 0 ); - - /** - * Destroys the collection delete job. - */ - ~CollectionDeleteJob(); - - protected: - virtual void doStart(); - - private: - Q_DECLARE_PRIVATE( CollectionDeleteJob ) -}; - -} - -#endif diff --git a/akonadi/collectiondisplayattribute.cpp b/akonadi/collectiondisplayattribute.cpp deleted file mode 100644 index 48df749c8..000000000 --- a/akonadi/collectiondisplayattribute.cpp +++ /dev/null @@ -1,98 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "collectiondisplayattribute.h" - -#include "imapparser_p.h" - -#include - -using namespace Akonadi; - -class CollectionDisplayAttribute::Private -{ - public: - QString name; - QString icon; -}; - -CollectionDisplayAttribute::CollectionDisplayAttribute() : - d( new Private ) -{ -} - -CollectionDisplayAttribute::~ CollectionDisplayAttribute() -{ - delete d; -} - -QString CollectionDisplayAttribute::displayName() const -{ - return d->name; -} - -void CollectionDisplayAttribute::setDisplayName(const QString & name) -{ - d->name = name; -} - -KIcon CollectionDisplayAttribute::icon() const -{ - return KIcon( d->icon ); -} - -QString CollectionDisplayAttribute::iconName() const -{ - return d->icon; -} - -void CollectionDisplayAttribute::setIconName(const QString & icon) -{ - d->icon = icon; -} - -QByteArray Akonadi::CollectionDisplayAttribute::type() const -{ - return "COLDISPLAY"; -} - -CollectionDisplayAttribute * CollectionDisplayAttribute::clone() const -{ - CollectionDisplayAttribute *attr = new CollectionDisplayAttribute(); - attr->d->name = d->name; - attr->d->icon = d->icon; - return attr; -} - -QByteArray CollectionDisplayAttribute::serialized() const -{ - QList l; - l << ImapParser::quote( d->name.toUtf8() ); - l << ImapParser::quote( d->icon.toUtf8() ); - return '(' + ImapParser::join( l, " " ) + ')'; -} - -void CollectionDisplayAttribute::deserialize(const QByteArray &data) -{ - QList l; - ImapParser::parseParenthesizedList( data, l ); - Q_ASSERT( l.count() >= 2 ); - d->name = QString::fromUtf8( l[0] ); - d->icon = QString::fromUtf8( l[1] ); -} diff --git a/akonadi/collectiondisplayattribute.h b/akonadi/collectiondisplayattribute.h deleted file mode 100644 index e1af92d4c..000000000 --- a/akonadi/collectiondisplayattribute.h +++ /dev/null @@ -1,88 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_COLLECTIONDISPLAYATTRIBUTE_H -#define AKONADI_COLLECTIONDISPLAYATTRIBUTE_H - -#include - -class KIcon; - -namespace Akonadi { - -/** - * Display properties of a collection, such as translated names and icons. - * @todo add active icon, eg. when folder contains unread mail - * @since 4.2 - */ -class AKONADI_EXPORT CollectionDisplayAttribute : public Attribute -{ - public: - /** - * Creates a new collection display attribute. - */ - CollectionDisplayAttribute(); - - /** - * Destructor. - */ - ~CollectionDisplayAttribute(); - - /** - * Returns the name that should be used for display. - * Fall back to Collection::name() if this is empty. - */ - QString displayName() const; - - /** - * Set the display name. - */ - void setDisplayName( const QString &name ); - - /** - * Returns the icon that should be used for this collection. - */ - KIcon icon() const; - - /** - * Returns the icon name of the icon returned by icon(). - */ - QString iconName() const; - - /** - * Set the icon name for the collections default icon. - */ - void setIconName( const QString &icon ); - - /* reimpl */ - QByteArray type() const; - CollectionDisplayAttribute* clone() const; - QByteArray serialized() const; - void deserialize( const QByteArray &data ); - - private: - //@cond PRIVATE - class Private; - Private* const d; - //@endcond -}; - -} - -#endif diff --git a/akonadi/collectionfetchjob.cpp b/akonadi/collectionfetchjob.cpp deleted file mode 100644 index 8a07ed5f7..000000000 --- a/akonadi/collectionfetchjob.cpp +++ /dev/null @@ -1,197 +0,0 @@ -/* - Copyright (c) 2006 - 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "collectionfetchjob.h" - -#include "imapparser_p.h" -#include "job_p.h" -#include "protocolhelper.h" -#include "entity_p.h" - -#include - -#include -#include -#include - -using namespace Akonadi; - -class Akonadi::CollectionFetchJobPrivate : public JobPrivate -{ - public: - CollectionFetchJobPrivate( CollectionFetchJob *parent ) - : JobPrivate( parent ), - mUnsubscribed( false ) - { - } - - Q_DECLARE_PUBLIC( CollectionFetchJob ) - - CollectionFetchJob::Type mType; - Collection mBase; - Collection::List mBaseList; - Collection::List mCollections; - QString mResource; - Collection::List mPendingCollections; - QTimer *mEmitTimer; - bool mUnsubscribed; - - void timeout() - { - Q_Q( CollectionFetchJob ); - - mEmitTimer->stop(); // in case we are called by result() - if ( !mPendingCollections.isEmpty() ) { - emit q->collectionsReceived( mPendingCollections ); - mPendingCollections.clear(); - } - } -}; - -CollectionFetchJob::CollectionFetchJob( const Collection &collection, Type type, QObject *parent ) - : Job( new CollectionFetchJobPrivate( this ), parent ) -{ - Q_D( CollectionFetchJob ); - - Q_ASSERT( collection.isValid() ); - d->mBase = collection; - d->mType = type; - - d->mEmitTimer = new QTimer( this ); - d->mEmitTimer->setSingleShot( true ); - d->mEmitTimer->setInterval( 100 ); - connect( d->mEmitTimer, SIGNAL(timeout()), this, SLOT(timeout()) ); - connect( this, SIGNAL(result(KJob*)), this, SLOT(timeout()) ); -} - -CollectionFetchJob::CollectionFetchJob( const Collection::List & cols, QObject * parent ) - : Job( new CollectionFetchJobPrivate( this ), parent ) -{ - Q_D( CollectionFetchJob ); - - Q_ASSERT( !cols.isEmpty() ); - d->mBaseList = cols; - - d->mEmitTimer = new QTimer( this ); - d->mEmitTimer->setSingleShot( true ); - d->mEmitTimer->setInterval( 100 ); - connect( d->mEmitTimer, SIGNAL(timeout()), this, SLOT(timeout()) ); - connect( this, SIGNAL(result(KJob*)), this, SLOT(timeout()) ); -} - -CollectionFetchJob::~CollectionFetchJob() -{ -} - -Collection::List CollectionFetchJob::collections() const -{ - Q_D( const CollectionFetchJob ); - - return d->mCollections; -} - -void CollectionFetchJob::doStart() -{ - Q_D( CollectionFetchJob ); - - if ( !d->mBaseList.isEmpty() ) { - foreach ( const Collection &col, d->mBaseList ) { - new CollectionFetchJob( col, CollectionFetchJob::Base, this ); - } - return; - } - - QByteArray command = d->newTag(); - if ( d->mUnsubscribed ) - command += " X-AKLIST "; - else - command += " X-AKLSUB "; - command += QByteArray::number( d->mBase.id() ); - command += ' '; - switch ( d->mType ) { - case Base: - command += "0 ("; - break; - case FirstLevel: - command += "1 ("; - break; - case Recursive: - command += "INF ("; - break; - default: - Q_ASSERT( false ); - } - - if ( !d->mResource.isEmpty() ) { - command += "RESOURCE \""; - command += d->mResource.toUtf8(); - command += '"'; - } - - command += ")\n"; - d->writeData( command ); -} - -void CollectionFetchJob::doHandleResponse( const QByteArray & tag, const QByteArray & data ) -{ - Q_D( CollectionFetchJob ); - - if ( tag == "*" ) { - Collection collection; - ProtocolHelper::parseCollection( data, collection ); - if ( !collection.isValid() ) - return; - - collection.d_ptr->resetChangeLog(); - d->mCollections.append( collection ); - d->mPendingCollections.append( collection ); - if ( !d->mEmitTimer->isActive() ) - d->mEmitTimer->start(); - return; - } - kDebug( 5250 ) << "Unhandled server response" << tag << data; -} - -void CollectionFetchJob::setResource(const QString & resource) -{ - Q_D( CollectionFetchJob ); - - d->mResource = resource; -} - -void CollectionFetchJob::slotResult(KJob * job) -{ - Q_D( CollectionFetchJob ); - - CollectionFetchJob *list = dynamic_cast( job ); - Q_ASSERT( job ); - d->mCollections += list->collections(); - Job::slotResult( job ); - if ( !job->error() && !hasSubjobs() ) - emitResult(); -} - -void CollectionFetchJob::includeUnsubscribed(bool include) -{ - Q_D( CollectionFetchJob ); - - d->mUnsubscribed = include; -} - -#include "collectionfetchjob.moc" diff --git a/akonadi/collectionfetchjob.h b/akonadi/collectionfetchjob.h deleted file mode 100644 index 7dfb66849..000000000 --- a/akonadi/collectionfetchjob.h +++ /dev/null @@ -1,135 +0,0 @@ -/* - Copyright (c) 2006 - 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_COLLECTIONFETCHJOB_H -#define AKONADI_COLLECTIONFETCHJOB_H - -#include "akonadi_export.h" -#include -#include - -namespace Akonadi { - -class CollectionFetchJobPrivate; - -/** - * @short Job that fetches collections from the Akonadi storage. - * - * This class can be used to retrieve the complete or partial collection tree - * from the Akonadi storage. - * - * @code - * - * using namespace Akonadi; - * - * // fetching all collections recursive, starting at the root collection - * CollectionFetchJob *job = new CollectionFetchJob( Collection::root(), CollectionFetchJob::Recursive ); - * if ( job->exec() ) { - * Collection::List collections = job->collections(); - * foreach( const Collection &collection, collections ) { - * qDebug() << "Name:" << collection.name(); - * } - * } - * - * @endcode - * - * @author Volker Krause - */ -class AKONADI_EXPORT CollectionFetchJob : public Job -{ - Q_OBJECT - - public: - /** - * Describes the type of fetch depth. - */ - enum Type - { - Base, ///< Only fetch the base collection. - FirstLevel, ///< Only list direct sub-collections of the base collection. - Recursive ///< List all sub-collections. - }; - - /** - * Creates a new collection fetch job. - * - * @param collection The base collection for the listing. Must be valid. - * @param type The type of fetch depth. - * @param parent The parent object. - */ - explicit CollectionFetchJob( const Collection &collection, Type type = FirstLevel, QObject *parent = 0 ); - - /** - * Creates a new collection fetch job to retrieve a list of collections. - * - * @param collections A list of collections to fetch. Must not be empty, content must be valid. - * @param parent The parent object. - */ - explicit CollectionFetchJob( const Collection::List &collections, QObject *parent = 0 ); - - /** - * Destroys the collection fetch job. - */ - virtual ~CollectionFetchJob(); - - /** - * Returns the list of fetched collection. - */ - Collection::List collections() const; - - /** - * Sets a resource identifier to limit collection listing to one resource. - * - * @param resource The resource identifier. - */ - void setResource( const QString &resource ); - - /** - * Include also unsubscribed collections. - */ - void includeUnsubscribed( bool include = true ); - - Q_SIGNALS: - /** - * This signal is emitted whenever the job has received collections. - * - * @param collections The received collections. - */ - void collectionsReceived( const Akonadi::Collection::List &collections ); - - protected: - virtual void doStart(); - virtual void doHandleResponse( const QByteArray &tag, const QByteArray &data ); - - protected Q_SLOTS: - //@cond PRIVATE - void slotResult( KJob* job ); - //@endcond - - private: - Q_DECLARE_PRIVATE( CollectionFetchJob ) - - //@cond PRIVATE - Q_PRIVATE_SLOT( d_func(), void timeout() ) - //@endcond -}; - -} - -#endif diff --git a/akonadi/collectionfilterproxymodel.cpp b/akonadi/collectionfilterproxymodel.cpp deleted file mode 100644 index 84bcc45da..000000000 --- a/akonadi/collectionfilterproxymodel.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - Copyright (c) 2007 Bruno Virlet - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "collectionfilterproxymodel.h" - -#include "collectionmodel.h" - -#include - -#include -#include - -using namespace Akonadi; - -/** - * @internal - */ -class CollectionFilterProxyModel::Private -{ - public: - Private( CollectionFilterProxyModel *parent ) - : mParent( parent ) - { - mimeTypes << QLatin1String( "text/uri-list" ); - } - - bool collectionAccepted( const QModelIndex &index ); - - CollectionFilterProxyModel *mParent; - QStringList mimeTypes; -}; - -bool CollectionFilterProxyModel::Private::collectionAccepted( const QModelIndex &index ) -{ - // Retrieve supported mimetypes - QStringList collectionMimeTypes = mParent->sourceModel()->data( index, CollectionModel::CollectionRole ).value().contentMimeTypes(); - - // If this collection directly contains one valid mimetype, it is accepted - foreach ( const QString &type, collectionMimeTypes ) { - if ( mimeTypes.contains( type ) ) - return true; - - KMimeType::Ptr mimeType = KMimeType::mimeType( type, KMimeType::ResolveAliases ); - if ( !mimeType.isNull() ) { - foreach ( const QString &mt, mimeTypes ) { - if ( mimeType->is( mt ) ) - return true; - } - } - } - // If this collection has a child which contains valid mimetypes, it is accepted - QModelIndex childIndex = index.child( 0, 0 ); - while ( childIndex.isValid() ) { - if ( collectionAccepted( childIndex ) ) - return true; - - childIndex = childIndex.sibling( childIndex.row() + 1, 0 ); - } - - // Or else, no reason to keep this collection. - return false; -} - - -CollectionFilterProxyModel::CollectionFilterProxyModel( QObject *parent ) - : QSortFilterProxyModel( parent ), - d( new Private( this ) ) -{ - setSupportedDragActions( Qt::CopyAction | Qt::MoveAction ); -} - -CollectionFilterProxyModel::~CollectionFilterProxyModel() -{ - delete d; -} - -void CollectionFilterProxyModel::addMimeTypeFilters(const QStringList &typeList) -{ - d->mimeTypes << typeList; - invalidateFilter(); -} - -void CollectionFilterProxyModel::addMimeTypeFilter(const QString &type) -{ - d->mimeTypes << type; - invalidateFilter(); -} - -bool CollectionFilterProxyModel::filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent) const -{ - return d->collectionAccepted( sourceModel()->index( sourceRow, 0, sourceParent ) ); -} - -QStringList CollectionFilterProxyModel::mimeTypeFilters() const -{ - return d->mimeTypes; -} - -void CollectionFilterProxyModel::clearFilters() -{ - d->mimeTypes.clear(); - invalidateFilter(); -} - -#include "collectionfilterproxymodel.moc" diff --git a/akonadi/collectionfilterproxymodel.h b/akonadi/collectionfilterproxymodel.h deleted file mode 100644 index 7ed88c926..000000000 --- a/akonadi/collectionfilterproxymodel.h +++ /dev/null @@ -1,107 +0,0 @@ -/* - Copyright (c) 2007 Bruno Virlet - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_COLLECTIONFILTERPROXYMODEL_H -#define AKONADI_COLLECTIONFILTERPROXYMODEL_H - -#include "akonadi_export.h" -#include - -namespace Akonadi { - -class CollectionModel; - -/** - * @short A proxy model that filters collections by mime type. - * - * This class can be used on top of a CollectionModel to filter out - * all collections that doesn't match a given mime type. - * - * For instance, a mail application will use addMimeType( "message/rfc822" ) to only show - * collections containing mail. - * - * @code - * - * Akonadi::CollectionModel *model = new Akonadi::CollectionModel( this ); - * - * Akonadi::CollectionFilterProxy *proxy = new Akonadi::CollectionFilterProxyModel(); - * proxy->addMimeTypeFilter( "message/rfc822" ); - * proxy->setSourceModel( model ); - * - * QTreeView *view = new QTreeView( this ); - * view->setModel( proxy ); - * - * @endcode - * - * @author Bruno Virlet - */ -class AKONADI_EXPORT CollectionFilterProxyModel : public QSortFilterProxyModel -{ - Q_OBJECT - - public: - /** - * Creates a new collection proxy filter model. - * - * @param parent The parent object. - */ - explicit CollectionFilterProxyModel( QObject *parent = 0 ); - - /** - * Destroys the collection proxy filter model. - */ - virtual ~CollectionFilterProxyModel(); - - /** - * Add mime types to be shown by the filter. - * - * @param mimeTypes A list of mime types to be shown. - */ - void addMimeTypeFilters( const QStringList &mimeTypes ); - - /** - * Add mime type to be shown by the filter. - * - * @param mimeType A mime type to be shown. - */ - void addMimeTypeFilter( const QString &mimeType ); - - /** - * Returns the list of mime type filters. - */ - QStringList mimeTypeFilters() const; - - /** - * Clear all mime type filters. - */ - void clearFilters(); - - protected: - virtual bool filterAcceptsRow( int sourceRow, const QModelIndex &sourceParent) const; - - private: - //@cond PRIVATE - class Private; - Private* const d; - //@endcond -}; - -} - -#endif diff --git a/akonadi/collectiongeneralpropertiespage.cpp b/akonadi/collectiongeneralpropertiespage.cpp deleted file mode 100644 index d78045783..000000000 --- a/akonadi/collectiongeneralpropertiespage.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "collectiongeneralpropertiespage.h" - -#include "collection.h" -#include "collectiondisplayattribute.h" -#include "collectionstatistics.h" -#include "collectionutils_p.h" - -#include - -using namespace Akonadi; - -CollectionGeneralPropertiesPage::CollectionGeneralPropertiesPage(QWidget * parent) : - CollectionPropertiesPage( parent ) -{ - setPageTitle( i18nc( "@title:tab general properties page", "General" ) ); - ui.setupUi( this ); -} - -void CollectionGeneralPropertiesPage::load(const Collection & collection) -{ - QString displayName; - QString iconName; - if ( collection.hasAttribute() ) { - displayName = collection.attribute()->displayName(); - iconName = collection.attribute()->iconName(); - } - - if ( displayName.isEmpty() ) - ui.nameEdit->setText( collection.name() ); - else - ui.nameEdit->setText( displayName ); - - if ( iconName.isEmpty() ) - ui.customIcon->setIcon( CollectionUtils::defaultIconName( collection ) ); - else - ui.customIcon->setIcon( iconName ); - ui.customIconCheckbox->setChecked( !iconName.isEmpty() ); - - if ( collection.statistics().count() >= 0 ) { - ui.countLabel->setText( i18ncp( "@label", "One object", "%1 objects", - collection.statistics().count() ) ); - } else { - ui.statsBox->hide(); - } -} - -void CollectionGeneralPropertiesPage::save(Collection & collection) -{ - if ( collection.hasAttribute() && - !collection.attribute()->displayName().isEmpty() ) - collection.attribute()->setDisplayName( ui.nameEdit->text() ); - else - collection.setName( ui.nameEdit->text() ); - - if ( ui.customIconCheckbox->isChecked() ) - collection.attribute( Collection::AddIfMissing )->setIconName( ui.customIcon->icon() ); - else if ( collection.hasAttribute() ) - collection.attribute()->setIconName( QString() ); -} - -#include "collectiongeneralpropertiespage.moc" diff --git a/akonadi/collectiongeneralpropertiespage.h b/akonadi/collectiongeneralpropertiespage.h deleted file mode 100644 index d45d72620..000000000 --- a/akonadi/collectiongeneralpropertiespage.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKOANDI_COLLECTIONGENERALPROPERTIESPAGE_H -#define AKOANDI_COLLECTIONGENERALPROPERTIESPAGE_H - -#include "collectionpropertiespage.h" -#include "ui_collectiongeneralpropertiespage.h" - -namespace Akonadi { - -/** - * @internal - */ -class CollectionGeneralPropertiesPage : public CollectionPropertiesPage -{ - Q_OBJECT - public: - explicit CollectionGeneralPropertiesPage( QWidget *parent = 0 ); - - void load( const Collection &collection ); - void save( Collection &collection ); - - private: - Ui::CollectionGeneralPropertiesPage ui; -}; - -} - -#endif diff --git a/akonadi/collectiongeneralpropertiespage.ui b/akonadi/collectiongeneralpropertiespage.ui deleted file mode 100644 index 7c63b2b13..000000000 --- a/akonadi/collectiongeneralpropertiespage.ui +++ /dev/null @@ -1,142 +0,0 @@ - - CollectionGeneralPropertiesPage - - - - 0 - 0 - 400 - 300 - - - - - - - &Name: - - - nameEdit - - - - - - - - - - &Use custom icon: - - - - - - - false - - - folder - - - 16 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - - - - Statistics - - - - - - Content: - - - - - - - 0 objects - - - - - - - Size: - - - - - - - 0 Byte - - - - - - - - - - Qt::Vertical - - - - 20 - 40 - - - - - - - - - KIconButton - QPushButton -
kicondialog.h
-
- - KLineEdit - QLineEdit -
klineedit.h
-
-
- - - - customIconCheckbox - toggled(bool) - customIcon - setEnabled(bool) - - - 115 - 55 - - - 245 - 55 - - - - -
diff --git a/akonadi/collectionmodel.cpp b/akonadi/collectionmodel.cpp deleted file mode 100644 index 6f4b78c08..000000000 --- a/akonadi/collectionmodel.cpp +++ /dev/null @@ -1,291 +0,0 @@ -/* - Copyright (c) 2006 - 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "collectionmodel.h" -#include "collectionmodel_p.h" - -#include "collectionutils_p.h" -#include "collectionmodifyjob.h" -#include "collectiondisplayattribute.h" -#include "monitor.h" -#include "pastehelper.h" -#include "session.h" - -#include -#include -#include -#include - -#include -#include - -using namespace Akonadi; - -CollectionModel::CollectionModel( QObject * parent ) : - QAbstractItemModel( parent ), - d_ptr( new CollectionModelPrivate( this ) ) -{ - Q_D( CollectionModel ); - d->init(); -} - -CollectionModel::CollectionModel( CollectionModelPrivate *d, - QObject *parent ) - : QAbstractItemModel( parent ), - d_ptr( d ) -{ - d->init(); -} - -CollectionModel::~CollectionModel() -{ - Q_D( CollectionModel ); - d->childCollections.clear(); - d->collections.clear(); - - delete d->monitor; - d->monitor = 0; - - delete d; -} - -int CollectionModel::columnCount( const QModelIndex & parent ) const -{ - if (parent.isValid() && parent.column() != 0) - return 0; - return 1; -} - -QVariant CollectionModel::data( const QModelIndex & index, int role ) const -{ - Q_D( const CollectionModel ); - if ( !index.isValid() ) - return QVariant(); - - const Collection col = d->collections.value( index.internalId() ); - if ( !col.isValid() ) - return QVariant(); - - if ( index.column() == 0 && (role == Qt::DisplayRole || role == Qt::EditRole) ) { - if ( col.hasAttribute() && - !col.attribute()->displayName().isEmpty() ) - return col.attribute()->displayName(); - return col.name(); - } - - switch ( role ) { - case Qt::DecorationRole: - if ( index.column() == 0 ) { - if ( col.hasAttribute() && - !col.attribute()->iconName().isEmpty() ) - return col.attribute()->icon(); - return KIcon( CollectionUtils::defaultIconName( col ) ); - } - break; - case CollectionIdRole: - return col.id(); - case CollectionRole: - return QVariant::fromValue( col ); - } - return QVariant(); -} - -QModelIndex CollectionModel::index( int row, int column, const QModelIndex & parent ) const -{ - Q_D( const CollectionModel ); - if (column >= columnCount() || column < 0) return QModelIndex(); - - QList list; - if ( !parent.isValid() ) - list = d->childCollections.value( Collection::root().id() ); - else - { - if (parent.column() > 0) - return QModelIndex(); - list = d->childCollections.value( parent.internalId() ); - } - - if ( row < 0 || row >= list.size() ) - return QModelIndex(); - if ( !d->collections.contains( list.at(row) ) ) - return QModelIndex(); - return createIndex( row, column, reinterpret_cast( d->collections.value( list.at(row) ).id() ) ); -} - -QModelIndex CollectionModel::parent( const QModelIndex & index ) const -{ - Q_D( const CollectionModel ); - if ( !index.isValid() ) - return QModelIndex(); - - Collection col = d->collections.value( index.internalId() ); - if ( !col.isValid() ) - return QModelIndex(); - - Collection parentCol = d->collections.value( col.parent() ); - if ( !parentCol.isValid() ) - return QModelIndex(); - - QList list; - list = d->childCollections.value( parentCol.parent() ); - - int parentRow = list.indexOf( parentCol.id() ); - if ( parentRow < 0 ) - return QModelIndex(); - - return createIndex( parentRow, 0, reinterpret_cast( parentCol.id() ) ); -} - -int CollectionModel::rowCount( const QModelIndex & parent ) const -{ - const Q_D( CollectionModel ); - QList list; - if ( parent.isValid() ) - list = d->childCollections.value( parent.internalId() ); - else - list = d->childCollections.value( Collection::root().id() ); - - return list.size(); -} - -QVariant CollectionModel::headerData( int section, Qt::Orientation orientation, int role ) const -{ - if ( section == 0 && orientation == Qt::Horizontal && role == Qt::DisplayRole ) - return i18nc( "@title:column, name of a thing", "Name" ); - return QAbstractItemModel::headerData( section, orientation, role ); -} - -bool CollectionModel::setData( const QModelIndex & index, const QVariant & value, int role ) -{ - Q_D( CollectionModel ); - if ( index.column() == 0 && role == Qt::EditRole ) { - // rename collection - Collection col = d->collections.value( index.internalId() ); - if ( !col.isValid() || value.toString().isEmpty() ) - return false; - col.setName( value.toString() ); - CollectionModifyJob *job = new CollectionModifyJob( col, d->session ); - connect( job, SIGNAL(result(KJob*)), SLOT(editDone(KJob*)) ); - return true; - } - return QAbstractItemModel::setData( index, value, role ); -} - -Qt::ItemFlags CollectionModel::flags( const QModelIndex & index ) const -{ - Q_D( const CollectionModel ); - Qt::ItemFlags flags = QAbstractItemModel::flags( index ); - - flags = flags | Qt::ItemIsDragEnabled; - - Collection col; - if ( index.isValid() ) { - col = d->collections.value( index.internalId() ); - Q_ASSERT( col.isValid() ); - } - else - return flags | Qt::ItemIsDropEnabled; // HACK Workaround for a probable bug in Qt - - if ( col.isValid() ) { - if ( col.rights() & (Collection::CanChangeCollection | - Collection::CanCreateCollection | - Collection::CanDeleteCollection | - Collection::CanCreateItem) ) { - if ( index.column() == 0 ) - flags = flags | Qt::ItemIsEditable; - - flags = flags | Qt::ItemIsDropEnabled; - } - } - - return flags; -} - -Qt::DropActions CollectionModel::supportedDropActions() const -{ - return Qt::CopyAction | Qt::MoveAction; -} - -QStringList CollectionModel::mimeTypes() const -{ - return QStringList() << QLatin1String( "text/uri-list" ); -} - -QMimeData *CollectionModel::mimeData(const QModelIndexList &indexes) const -{ - QMimeData *data = new QMimeData(); - KUrl::List urls; - foreach ( const QModelIndex &index, indexes ) { - if ( index.column() != 0 ) - continue; - - urls << Collection( index.internalId() ).url(); - } - urls.populateMimeData( data ); - - return data; -} - -bool CollectionModel::dropMimeData(const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent) -{ - Q_D( CollectionModel ); - if ( !(action & supportedDropActions()) ) - return false; - - // handle drops onto items as well as drops between items - QModelIndex idx; - if ( row >= 0 && column >= 0 ) - idx = index( row, column, parent ); - else - idx = parent; - - if ( !idx.isValid() ) - return false; - - const Collection parentCol = d->collections.value( idx.internalId() ); - if (!parentCol.isValid()) - return false; - - KJob *job = PasteHelper::paste( data, parentCol, action != Qt::MoveAction ); - connect( job, SIGNAL(result(KJob*)), SLOT(dropResult(KJob*)) ); - return true; -} - -Collection CollectionModel::collectionForId(Collection::Id id) const -{ - Q_D( const CollectionModel ); - return d->collections.value( id ); -} - -void CollectionModel::fetchCollectionStatistics(bool enable) -{ - Q_D( CollectionModel ); - d->fetchStatistics = enable; - d->monitor->fetchCollectionStatistics( enable ); -} - -void CollectionModel::includeUnsubscribed(bool include) -{ - Q_D( CollectionModel ); - d->unsubscribed = include; -} - - - -#include "collectionmodel.moc" diff --git a/akonadi/collectionmodel.h b/akonadi/collectionmodel.h deleted file mode 100644 index 440bdfb79..000000000 --- a/akonadi/collectionmodel.h +++ /dev/null @@ -1,136 +0,0 @@ -/* - Copyright (c) 2006 - 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_COLLECTIONMODEL_H -#define AKONADI_COLLECTIONMODEL_H - -#include "akonadi_export.h" - -#include - -#include - -namespace Akonadi { - -class CollectionModelPrivate; - -/** - * @short A model for collections. - * - * This class provides the interface of QAbstractItemModel for the - * collection tree of the Akonadi storage. - * - * @code - * - * Akonadi::CollectionModel *model = new Akonadi::CollectionModel( this ); - * - * QTreeView *view = new QTreeView( this ); - * view->setModel( model ); - * - * @endcode - * - * If you want to list only collections of a special mime type, use - * CollectionFilterProxyModel on top of this model. - * - * @author Volker Krause - */ -class AKONADI_EXPORT CollectionModel : public QAbstractItemModel -{ - Q_OBJECT - - public: - /** - * Describes the roles for collections. - */ - enum Roles { - CollectionIdRole = Qt::UserRole + 1, ///< The collection identifier. - CollectionRole, ///< The actual collection object. - UserRole = Qt::UserRole + 42 ///< Role for user extensions. - }; - - /** - * Creates a new collection model. - * - * @param parent The parent object. - */ - explicit CollectionModel( QObject *parent = 0 ); - - /** - * Destroys the collection model. - */ - virtual ~CollectionModel(); - - /** - * Sets whether collection statistics information shall be provided - * by the model. - * - * @see CollectionStatistics. - */ - void fetchCollectionStatistics( bool enable ); - - /** - * Sets whether unsubscribed collections shall be listed in the model. - */ - void includeUnsubscribed( bool include = true ); - - virtual int columnCount( const QModelIndex & parent = QModelIndex() ) const; - virtual QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) const; - virtual QModelIndex index( int row, int column, const QModelIndex & parent = QModelIndex() ) const; - virtual QModelIndex parent( const QModelIndex & index ) const; - virtual int rowCount( const QModelIndex & parent = QModelIndex() ) const; - virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; - virtual bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ); - virtual Qt::ItemFlags flags( const QModelIndex &index ) const; - virtual Qt::DropActions supportedDropActions() const; - virtual QMimeData *mimeData( const QModelIndexList &indexes ) const; - virtual bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ); - virtual QStringList mimeTypes() const; - - protected: - /** - * Returns the collection for a given collection @p id. - */ - Collection collectionForId( Collection::Id id ) const; - - //@cond PRIVATE - Akonadi::CollectionModelPrivate *d_ptr; - explicit CollectionModel( CollectionModelPrivate *d, QObject *parent = 0 ); - //@endcond - - private: - Q_DECLARE_PRIVATE( CollectionModel ) - - //@cond PRIVATE - Q_PRIVATE_SLOT( d_func(), void startFirstListJob() ) - Q_PRIVATE_SLOT( d_func(), void collectionRemoved( const Akonadi::Collection& ) ) - Q_PRIVATE_SLOT( d_func(), void collectionChanged( const Akonadi::Collection& ) ) - Q_PRIVATE_SLOT( d_func(), void updateDone( KJob* ) ) - Q_PRIVATE_SLOT( d_func(), void collectionStatisticsChanged( - Akonadi::Collection::Id, - const Akonadi::CollectionStatistics& ) ) - Q_PRIVATE_SLOT( d_func(), void listDone( KJob* ) ) - Q_PRIVATE_SLOT( d_func(), void editDone( KJob* ) ) - Q_PRIVATE_SLOT( d_func(), void dropResult( KJob* ) ) - Q_PRIVATE_SLOT( d_func(), void collectionsChanged( const Akonadi::Collection::List& ) ) - //@endcond -}; - -} - -#endif diff --git a/akonadi/collectionmodel_p.cpp b/akonadi/collectionmodel_p.cpp deleted file mode 100644 index c6c231bee..000000000 --- a/akonadi/collectionmodel_p.cpp +++ /dev/null @@ -1,277 +0,0 @@ -/* - Copyright (c) 2006 - 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -//@cond PRIVATE - -#include "collectionmodel_p.h" -#include "collectionmodel.h" -#include "collectionutils_p.h" - -#include "collectionfetchjob.h" -#include "collectionstatistics.h" -#include "collectionstatisticsjob.h" -#include "monitor.h" -#include "session.h" - -#include -#include -#include - -#include - -using namespace Akonadi; - - -void CollectionModelPrivate::collectionRemoved( const Akonadi::Collection &collection ) -{ - Q_Q( CollectionModel ); - QModelIndex colIndex = indexForId( collection.id() ); - if ( colIndex.isValid() ) { - QModelIndex parentIndex = q->parent( colIndex ); - // collection is still somewhere in the hierarchy - removeRowFromModel( colIndex.row(), parentIndex ); - } else { - if ( collections.contains( collection.id() ) ) { - // collection is orphan, ie. the parent has been removed already - collections.remove( collection.id() ); - childCollections.remove( collection.id() ); - } - } -} - -void CollectionModelPrivate::collectionChanged( const Akonadi::Collection &collection ) -{ - Q_Q( CollectionModel ); - - // What kind of change is it ? - Collection::Id oldParentId = collections.value( collection.id() ).parent(); - Collection::Id newParentId = collection.parent(); - if ( newParentId != oldParentId && oldParentId >= 0 ) { // It's a move - removeRowFromModel( indexForId( collections[ collection.id() ].id() ).row(), indexForId( oldParentId ) ); - Collection newParent; - if ( newParentId == Collection::root().id() ) - newParent = Collection::root(); - else - newParent = collections.value( newParentId ); - CollectionFetchJob *job = new CollectionFetchJob( newParent, CollectionFetchJob::Recursive, session ); - job->includeUnsubscribed( unsubscribed ); - q->connect( job, SIGNAL(collectionsReceived(Akonadi::Collection::List)), - q, SLOT(collectionsChanged(Akonadi::Collection::List)) ); - q->connect( job, SIGNAL( result( KJob* ) ), - q, SLOT( listDone( KJob* ) ) ); - - } - else { // It's a simple change - CollectionFetchJob *job = new CollectionFetchJob( collection, CollectionFetchJob::Base, session ); - job->includeUnsubscribed( unsubscribed ); - q->connect( job, SIGNAL(collectionsReceived(Akonadi::Collection::List)), - q, SLOT(collectionsChanged(Akonadi::Collection::List)) ); - q->connect( job, SIGNAL( result( KJob* ) ), - q, SLOT( listDone( KJob* ) ) ); - } - -} - -void CollectionModelPrivate::updateDone( KJob *job ) -{ - if ( job->error() ) { - // TODO: handle job errors - kWarning( 5250 ) << "Job error:" << job->errorString(); - } else { - CollectionStatisticsJob *csjob = static_cast( job ); - Collection result = csjob->collection(); - collectionStatisticsChanged( result.id(), csjob->statistics() ); - } -} - -void CollectionModelPrivate::collectionStatisticsChanged( Collection::Id collection, - const Akonadi::CollectionStatistics &statistics ) -{ - Q_Q( CollectionModel ); - - if ( !collections.contains( collection ) ) - kWarning( 5250 ) << "Got statistics response for non-existing collection:" << collection; - else { - collections[ collection ].setStatistics( statistics ); - - Collection col = collections.value( collection ); - QModelIndex startIndex = indexForId( col.id() ); - QModelIndex endIndex = indexForId( col.id(), q->columnCount( q->parent( startIndex ) ) - 1 ); - emit q->dataChanged( startIndex, endIndex ); - } -} - -void CollectionModelPrivate::listDone( KJob *job ) -{ - if ( job->error() ) { - kWarning( 5250 ) << "Job error: " << job->errorString() << endl; - } -} - -void CollectionModelPrivate::editDone( KJob * job ) -{ - if ( job->error() ) { - kWarning( 5250 ) << "Edit failed: " << job->errorString(); - } -} - -void CollectionModelPrivate::dropResult(KJob * job) -{ - if ( job->error() ) { - kWarning( 5250 ) << "Paste failed:" << job->errorString(); - // TODO: error handling - } -} - -void CollectionModelPrivate::collectionsChanged( const Collection::List &cols ) -{ - Q_Q( CollectionModel ); - foreach( Collection col, cols ) { - if ( collections.contains( col.id() ) ) { - // collection already known - col.setStatistics( collections.value( col.id() ).statistics() ); - collections[ col.id() ] = col; - QModelIndex startIndex = indexForId( col.id() ); - QModelIndex endIndex = indexForId( col.id(), q->columnCount( q->parent( startIndex ) ) - 1 ); - emit q->dataChanged( startIndex, endIndex ); - continue; - } - collections.insert( col.id(), col ); - QModelIndex parentIndex = indexForId( col.parent() ); - if ( parentIndex.isValid() || col.parent() == Collection::root().id() ) { - q->beginInsertRows( parentIndex, q->rowCount( parentIndex ), q->rowCount( parentIndex ) ); - childCollections[ col.parent() ].append( col.id() ); - q->endInsertRows(); - } else { - childCollections[ col.parent() ].append( col.id() ); - } - - updateSupportedMimeTypes( col ); - - // start a statistics job for every collection to get message counts, etc. - if ( fetchStatistics && !CollectionUtils::isVirtualParent( col ) ) { - CollectionStatisticsJob* csjob = new CollectionStatisticsJob( col, session ); - q->connect( csjob, SIGNAL(result(KJob*)), q, SLOT(updateDone(KJob*)) ); - } - } -} - -QModelIndex CollectionModelPrivate::indexForId( Collection::Id id, int column ) -{ - Q_Q( CollectionModel ); - if ( !collections.contains( id ) ) - return QModelIndex(); - - Collection::Id parentId = collections.value( id ).parent(); - // check if parent still exist or if this is an orphan collection - if ( parentId != Collection::root().id() && !collections.contains( parentId ) ) - return QModelIndex(); - - QList list = childCollections.value( parentId ); - int row = list.indexOf( id ); - - if ( row >= 0 ) - return q->createIndex( row, column, reinterpret_cast( collections.value( list.at(row) ).id() ) ); - return QModelIndex(); -} - -bool CollectionModelPrivate::removeRowFromModel( int row, const QModelIndex & parent ) -{ - Q_Q( CollectionModel ); - QList list; - Collection parentCol; - if ( parent.isValid() ) { - parentCol = collections.value( parent.internalId() ); - Q_ASSERT( parentCol.id() == parent.internalId() ); - list = childCollections.value( parentCol.id() ); - } else { - parentCol = Collection::root(); - list = childCollections.value( Collection::root().id() ); - } - if ( row < 0 || row >= list.size() ) { - kWarning( 5250 ) << "Index out of bounds:" << row <<" parent:" << parentCol.id(); - return false; - } - - q->beginRemoveRows( parent, row, row ); - Collection::Id delColId = list.takeAt( row ); - foreach( Collection::Id childColId, childCollections[ delColId ] ) - collections.remove( childColId ); - collections.remove( delColId ); - childCollections.remove( delColId ); // remove children of deleted collection - childCollections.insert( parentCol.id(), list ); // update children of parent - q->endRemoveRows(); - - return true; -} - -bool CollectionModelPrivate::supportsContentType(const QModelIndex & index, const QStringList & contentTypes) -{ - if ( !index.isValid() ) - return false; - Collection col = collections.value( index.internalId() ); - Q_ASSERT( col.isValid() ); - QStringList ct = col.contentMimeTypes(); - foreach ( const QString &a, ct ) { - if ( contentTypes.contains( a ) ) - return true; - } - return false; -} - -void CollectionModelPrivate::init() -{ - Q_Q( CollectionModel ); - - session = new Session( QByteArray("CollectionModel-") + QByteArray::number( qrand() ), q ); - QTimer::singleShot( 0, q, SLOT(startFirstListJob()) ); - - // monitor collection changes - monitor = new Monitor(); - monitor->setCollectionMonitored( Collection::root() ); - monitor->fetchCollection( true ); - - // ### Hack to get the kmail resource folder icons - KIconLoader::global()->addAppDir( QLatin1String( "kmail" ) ); - KIconLoader::global()->addAppDir( QLatin1String( "kdepim" ) ); - - // monitor collection changes - q->connect( monitor, SIGNAL(collectionChanged(const Akonadi::Collection&)), - q, SLOT(collectionChanged(const Akonadi::Collection&)) ); - q->connect( monitor, SIGNAL(collectionAdded(Akonadi::Collection,Akonadi::Collection)), - q, SLOT(collectionChanged(Akonadi::Collection)) ); - q->connect( monitor, SIGNAL(collectionRemoved(Akonadi::Collection)), - q, SLOT(collectionRemoved(Akonadi::Collection)) ); - q->connect( monitor, SIGNAL(collectionStatisticsChanged(Akonadi::Collection::Id,Akonadi::CollectionStatistics)), - q, SLOT(collectionStatisticsChanged(Akonadi::Collection::Id,Akonadi::CollectionStatistics)) ); -} - -void CollectionModelPrivate::startFirstListJob() -{ - Q_Q( CollectionModel ); - - // start a list job - CollectionFetchJob *job = new CollectionFetchJob( Collection::root(), CollectionFetchJob::Recursive, session ); - job->includeUnsubscribed( unsubscribed ); - q->connect( job, SIGNAL(collectionsReceived(Akonadi::Collection::List)), - q, SLOT(collectionsChanged(Akonadi::Collection::List)) ); - q->connect( job, SIGNAL(result(KJob*)), q, SLOT(listDone(KJob*)) ); -} - -//@endcond diff --git a/akonadi/collectionmodel_p.h b/akonadi/collectionmodel_p.h deleted file mode 100644 index 4121ad6b1..000000000 --- a/akonadi/collectionmodel_p.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - Copyright (c) 2006 - 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_COLLECTIONMODEL_P_H -#define AKONADI_COLLECTIONMODEL_P_H - -#include "collection.h" - -#include -#include -#include -#include - -class KJob; - -namespace Akonadi { - - -class CollectionModel; -class CollectionStatistics; -class Monitor; -class Session; - -/** - * @internal - */ -class CollectionModelPrivate -{ - public: - Q_DECLARE_PUBLIC( CollectionModel ) - CollectionModelPrivate( CollectionModel *parent ) - : q_ptr( parent ), fetchStatistics( false ), unsubscribed( false ) - { - } - - virtual ~CollectionModelPrivate() {} - - CollectionModel *q_ptr; - QHash collections; - QHash > childCollections; - Monitor *monitor; - Session *session; - QStringList mimeTypes; - bool fetchStatistics; - bool unsubscribed; - - void init(); - void startFirstListJob(); - void collectionRemoved( const Akonadi::Collection& ); - void collectionChanged( const Akonadi::Collection& ); - void updateDone( KJob* ); - void collectionStatisticsChanged( Collection::Id, const Akonadi::CollectionStatistics& ); - void listDone( KJob* ); - void editDone( KJob* ); - void dropResult( KJob* ); - void collectionsChanged( const Akonadi::Collection::List &cols ); - - QModelIndex indexForId( Collection::Id id, int column = 0 ); - bool removeRowFromModel( int row, const QModelIndex & parent = QModelIndex() ); - bool supportsContentType( const QModelIndex &index, const QStringList &contentTypes ); - - private: - void updateSupportedMimeTypes( Collection col ) - { - QStringList l = col.contentMimeTypes(); - for ( QStringList::ConstIterator it = l.constBegin(); it != l.constEnd(); ++it ) { - if ( (*it) == Collection::mimeType() ) - continue; - if ( !mimeTypes.contains( *it ) ) - mimeTypes << *it; - } - } -}; - -} - -#endif diff --git a/akonadi/collectionmodifyjob.cpp b/akonadi/collectionmodifyjob.cpp deleted file mode 100644 index f67692a5d..000000000 --- a/akonadi/collectionmodifyjob.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "collectionmodifyjob.h" -#include "imapparser_p.h" -#include "job_p.h" -#include "protocolhelper.h" -#include "collectionstatistics.h" -#include "collection_p.h" - -using namespace Akonadi; - -class Akonadi::CollectionModifyJobPrivate : public JobPrivate -{ - public: - CollectionModifyJobPrivate( CollectionModifyJob *parent ) - : JobPrivate( parent ) - { - } - - Collection mCollection; -}; - -CollectionModifyJob::CollectionModifyJob( const Collection &collection, QObject * parent ) - : Job( new CollectionModifyJobPrivate( this ), parent ) -{ - Q_D( CollectionModifyJob ); - - Q_ASSERT( collection.isValid() ); - d->mCollection = collection; -} - -CollectionModifyJob::~CollectionModifyJob() -{ -} - -void CollectionModifyJob::doStart() -{ - Q_D( CollectionModifyJob ); - - QByteArray command = d->newTag() + " MODIFY " + QByteArray::number( d->mCollection.id() ); - QByteArray changes; - if ( d->mCollection.d_func()->contentTypesChanged ) { - QList bList; - foreach( const QString &s, d->mCollection.contentMimeTypes() ) bList << s.toLatin1(); - changes += " MIMETYPE (" + ImapParser::join( bList, " " ) + ')'; - } - if ( d->mCollection.parent() >= 0 ) - changes += " PARENT " + QByteArray::number( d->mCollection.parent() ); - if ( !d->mCollection.name().isEmpty() ) - changes += " NAME " + ImapParser::quote( d->mCollection.name().toUtf8() ); - if ( !d->mCollection.remoteId().isNull() ) - changes += " REMOTEID " + ImapParser::quote( d->mCollection.remoteId().toUtf8() ); - if ( d->mCollection.d_func()->cachePolicyChanged ) - changes += ' ' + ProtocolHelper::cachePolicyToByteArray( d->mCollection.cachePolicy() ); - if ( d->mCollection.attributes().count() > 0 ) - changes += ' ' + ProtocolHelper::attributesToByteArray( d->mCollection ); - foreach ( const QByteArray &b, d->mCollection.d_func()->mDeletedAttributes ) - changes += " -" + b; - if ( changes.isEmpty() ) { - emitResult(); - return; - } - command += changes + '\n'; - d->writeData( command ); -} - -#include "collectionmodifyjob.moc" diff --git a/akonadi/collectionmodifyjob.h b/akonadi/collectionmodifyjob.h deleted file mode 100644 index fa156766e..000000000 --- a/akonadi/collectionmodifyjob.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_COLLECTIONMODIFYJOB_H -#define AKONADI_COLLECTIONMODIFYJOB_H - -#include "akonadi_export.h" - -#include - -namespace Akonadi { - -class CachePolicy; -class Collection; -class CollectionModifyJobPrivate; - -/** - * @short Job that modifies a collection in the Akonadi storage. - * - * This job modifies the properties of an existing collection. - * - * @code - * - * Akonadi::Collection collection = ... - * - * Akonadi::CollectionModifyJob *job = new Akonadi::CollectionModifyJob( collection ); - * - * if ( job->exec() ) - * qDebug() << "Modified successfully"; - * else - * qDebug() << "Error occurred"; - * - * @endcode - * - * @author Volker Krause - */ -class AKONADI_EXPORT CollectionModifyJob : public Job -{ - Q_OBJECT - - public: - /** - * Creates a new collection modify job for the given collection. - * - * @param collection The collection to modify. - * @param parent The parent object. - */ - explicit CollectionModifyJob( const Collection &collection, QObject *parent = 0 ); - - /** - * Destroys the collection modify job. - */ - ~CollectionModifyJob(); - - protected: - virtual void doStart(); - - private: - Q_DECLARE_PRIVATE( CollectionModifyJob ) -}; - -} - -#endif diff --git a/akonadi/collectionpathresolver.cpp b/akonadi/collectionpathresolver.cpp deleted file mode 100644 index 0ce901ba4..000000000 --- a/akonadi/collectionpathresolver.cpp +++ /dev/null @@ -1,176 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "collectionpathresolver_p.h" - -#include "collectionfetchjob.h" -#include "job_p.h" - -#include - -#include - -using namespace Akonadi; - -class Akonadi::CollectionPathResolverPrivate : public JobPrivate -{ - public: - CollectionPathResolverPrivate( CollectionPathResolver *parent ) - : JobPrivate( parent ) - { - } - - void jobResult( KJob* ); - - Q_DECLARE_PUBLIC( CollectionPathResolver ) - - Collection::Id mColId; - QString mPath; - bool mPathToId; - QStringList mPathParts; - Collection mCurrentNode; -}; - -void CollectionPathResolverPrivate::jobResult(KJob *job ) -{ - if ( job->error() ) - return; - - Q_Q( CollectionPathResolver ); - - CollectionFetchJob *list = static_cast( job ); - CollectionFetchJob *nextJob = 0; - const Collection::List cols = list->collections(); - if ( cols.isEmpty() ) { - q->setError( CollectionPathResolver::Unknown ); - q->setErrorText( i18n( "No such collection.") ); - q->emitResult(); - return; - } - - if ( mPathToId ) { - const QString currentPart = mPathParts.takeFirst(); - bool found = false; - foreach ( const Collection &c, cols ) { - if ( c.name() == currentPart ) { - mCurrentNode = c; - found = true; - break; - } - } - if ( !found ) { - q->setError( CollectionPathResolver::Unknown ); - q->setErrorText( i18n( "No such collection.") ); - q->emitResult(); - return; - } - if ( mPathParts.isEmpty() ) { - mColId = mCurrentNode.id(); - q->emitResult(); - return; - } - nextJob = new CollectionFetchJob( mCurrentNode, CollectionFetchJob::FirstLevel, q ); - } else { - Collection col = list->collections().first(); - mCurrentNode = Collection( col.parent() ); - mPathParts.prepend( col.name() ); - if ( mCurrentNode == Collection::root() ) { - q->emitResult(); - return; - } - nextJob = new CollectionFetchJob( mCurrentNode, CollectionFetchJob::Base, q ); - } - q->connect( nextJob, SIGNAL(result(KJob*)), q, SLOT(jobResult(KJob*)) ); -} - -CollectionPathResolver::CollectionPathResolver(const QString & path, QObject * parent) - : Job( new CollectionPathResolverPrivate( this ), parent ) -{ - Q_D( CollectionPathResolver ); - - d->mPathToId = true; - d->mPath = path; - if ( d->mPath.startsWith( pathDelimiter() ) ) - d->mPath = d->mPath.right( d->mPath.length() - pathDelimiter().length() ); - if ( d->mPath.endsWith( pathDelimiter() ) ) - d->mPath = d->mPath.left( d->mPath.length() - pathDelimiter().length() ); - - d->mPathParts = d->mPath.split( pathDelimiter() ); - d->mCurrentNode = Collection::root(); -} - -CollectionPathResolver::CollectionPathResolver(const Collection & collection, QObject * parent) - : Job( new CollectionPathResolverPrivate( this ), parent ) -{ - Q_D( CollectionPathResolver ); - - d->mPathToId = false; - d->mColId = collection.id(); - d->mCurrentNode = collection; -} - -CollectionPathResolver::~CollectionPathResolver() -{ -} - -Collection::Id CollectionPathResolver::collection() const -{ - Q_D( const CollectionPathResolver ); - - return d->mColId; -} - -QString CollectionPathResolver::path() const -{ - Q_D( const CollectionPathResolver ); - - if ( d->mPathToId ) - return d->mPath; - return d->mPathParts.join( pathDelimiter() ); -} - -QString CollectionPathResolver::pathDelimiter() -{ - return QLatin1String( "/" ); -} - -void CollectionPathResolver::doStart() -{ - Q_D( CollectionPathResolver ); - - CollectionFetchJob *job = 0; - if ( d->mPathToId ) { - if ( d->mPath.isEmpty() ) { - d->mColId = Collection::root().id(); - emitResult(); - return; - } - job = new CollectionFetchJob( d->mCurrentNode, CollectionFetchJob::FirstLevel, this ); - } else { - if ( d->mColId == 0 ) { - d->mColId = Collection::root().id(); - emitResult(); - return; - } - job = new CollectionFetchJob( d->mCurrentNode, CollectionFetchJob::Base, this ); - } - connect( job, SIGNAL(result(KJob*)), SLOT(jobResult(KJob*)) ); -} - -#include "collectionpathresolver_p.moc" diff --git a/akonadi/collectionpathresolver_p.h b/akonadi/collectionpathresolver_p.h deleted file mode 100644 index 12a54ffdf..000000000 --- a/akonadi/collectionpathresolver_p.h +++ /dev/null @@ -1,97 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_COLLECTIONPATHRESOLVER_P_H -#define AKONADI_COLLECTIONPATHRESOLVER_P_H - -#include -#include - -namespace Akonadi { - -class CollectionPathResolverPrivate; - -/** - * @internal - * - * Converts between collection id and collection path. - * - * While it is generally recommended to use collection ids, it can - * be necessary in some cases (eg. a command line client) to use the - * collection path instead. Use this class to get a collection id - * from a collection path. - * - * @author Volker Krause - */ -class AKONADI_EXPORT CollectionPathResolver : public Job -{ - Q_OBJECT - - public: - /** - * Creates a new collection path resolver to convert a path into a id. - * - * @param path The collection path. - * @param parent The parent object. - */ - explicit CollectionPathResolver( const QString &path, QObject *parent = 0 ); - - /** - * Creates a new collection path resolver to determine the path of - * the given collection. - * - * @param collection The collection. - * @param parent The parent object. - */ - explicit CollectionPathResolver( const Collection &collection, QObject *parent = 0 ); - - /** - * Destroys the collection path resolver. - */ - ~CollectionPathResolver(); - - /** - * Returns the collection id. Only valid after the job succeeded. - */ - Collection::Id collection() const; - - /** - * Returns the collection path. Only valid after the job succeeded. - */ - QString path() const; - - /** - * Returns the path delimiter for collections. - */ - static QString pathDelimiter(); - - protected: - void doStart(); - - private: - Q_DECLARE_PRIVATE( CollectionPathResolver ) - - //@cond PRIVATE - Q_PRIVATE_SLOT( d_func(), void jobResult( KJob* ) ) - //@endcond -}; - -} - -#endif diff --git a/akonadi/collectionpropertiesdialog.cpp b/akonadi/collectionpropertiesdialog.cpp deleted file mode 100644 index d6efb3476..000000000 --- a/akonadi/collectionpropertiesdialog.cpp +++ /dev/null @@ -1,126 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "collectionpropertiesdialog.h" - -#include "cachepolicy.h" -#include "cachepolicypage.h" -#include "collection.h" -#include "collectiongeneralpropertiespage.h" -#include "collectionmodifyjob.h" - -#include -#include - -#include - -using namespace Akonadi; - -AKONADI_COLLECTION_PROPERTIES_PAGE_FACTORY(CollectionGeneralPropertiesPageFactory, CollectionGeneralPropertiesPage) - -/** - * @internal - */ -class CollectionPropertiesDialog::Private -{ - public: - Private( CollectionPropertiesDialog *parent ); - - static void registerBuiltinPages(); - - void save() - { - for ( int i = 0; i < tabWidget->count(); ++i ) { - CollectionPropertiesPage *page = static_cast( tabWidget->widget( i ) ); - page->save( collection ); - } - - CollectionModifyJob *job = new CollectionModifyJob( collection, q ); - connect( job, SIGNAL(result(KJob*)), q, SLOT(saveResult(KJob*)) ); - } - - void saveResult( KJob *job ) - { - if ( job->error() ) { - // TODO - kWarning() << job->errorString(); - } - q->deleteLater(); - } - - Collection collection; - KTabWidget* tabWidget; - CollectionPropertiesDialog *q; -}; - -typedef QList CollectionPropertiesPageFactoryList; - -K_GLOBAL_STATIC( CollectionPropertiesPageFactoryList, s_pages ) - -CollectionPropertiesDialog::Private::Private( CollectionPropertiesDialog *parent ) : q( parent ) -{ - if ( s_pages->isEmpty() ) - registerBuiltinPages(); -} - -void CollectionPropertiesDialog::Private::registerBuiltinPages() -{ - s_pages->append( new CollectionGeneralPropertiesPageFactory() ); - s_pages->append( new CachePolicyPageFactory() ); -} - - -CollectionPropertiesDialog::CollectionPropertiesDialog(const Collection & collection, QWidget * parent) : - KDialog( parent ), - d( new Private( this ) ) -{ - d->collection = collection; - - QBoxLayout *layout = new QHBoxLayout( mainWidget() ); - layout->setMargin( 0 ); - d->tabWidget = new KTabWidget( mainWidget() ); - layout->addWidget( d->tabWidget ); - - foreach ( CollectionPropertiesPageFactory *factory, *s_pages ) { - CollectionPropertiesPage *page = factory->createWidget( d->tabWidget ); - if ( page->canHandle( d->collection ) ) { - d->tabWidget->addTab( page, page->pageTitle() ); - page->load( d->collection ); - } else { - delete page; - } - } - - connect( this, SIGNAL(okClicked()), SLOT(save()) ); - connect( this, SIGNAL(cancelClicked()), SLOT(deleteLater()) ); -} - -CollectionPropertiesDialog::~CollectionPropertiesDialog() -{ - delete d; -} - -void CollectionPropertiesDialog::registerPage(CollectionPropertiesPageFactory * factory) -{ - if ( s_pages->isEmpty() ) - Private::registerBuiltinPages(); - s_pages->append( factory ); -} - -#include "collectionpropertiesdialog.moc" diff --git a/akonadi/collectionpropertiesdialog.h b/akonadi/collectionpropertiesdialog.h deleted file mode 100644 index c9fb947d0..000000000 --- a/akonadi/collectionpropertiesdialog.h +++ /dev/null @@ -1,94 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_COLLECTIONPROPERTIESDIALOG_H -#define AKONADI_COLLECTIONPROPERTIESDIALOG_H - -#include "akonadi_export.h" - -#include - -#include - -namespace Akonadi { - -class Collection; - -/** - * @short A generic and extensible dialog for collection properties. - * - * This dialog allows you to show or modify the properties of a collection. - * - * @code - * - * Akonadi::Collection collection = ... - * - * CollectionPropertiesDialog dlg( collection, this ); - * dlg.exec(); - * - * @endcode - * - * It can be extended by custom pages, which contains gui elements for custom - * properties. - * - * @see Akonadi::CollectionPropertiesPage - * - * @author Volker Krause - */ -class AKONADI_EXPORT CollectionPropertiesDialog : public KDialog -{ - Q_OBJECT - public: - /** - * Creates a new collection properties dialog. - * - * @param collection The collection which properties should be shown. - * @param parent The parent widget. - */ - explicit CollectionPropertiesDialog( const Collection &collection, QWidget *parent = 0 ); - - /** - * Destroys the collection properties dialog. - * - * @note Never call manually, the dialog is deleted automatically once all changes - * are written back to the Akonadi storage. - */ - ~CollectionPropertiesDialog(); - - /** - * Register custom pages for the collection properties dialog. - * - * @param factory The properties page factory that provides the custom page. - * - * @see Akonadi::CollectionPropertiesPageFactory - */ - static void registerPage( CollectionPropertiesPageFactory *factory ); - - private: - //@cond PRIVATE - class Private; - Private* const d; - Q_PRIVATE_SLOT( d, void save() ) - Q_PRIVATE_SLOT( d, void saveResult(KJob*) ) - //@endcond -}; - -} - -#endif diff --git a/akonadi/collectionpropertiespage.cpp b/akonadi/collectionpropertiespage.cpp deleted file mode 100644 index 1002b4f54..000000000 --- a/akonadi/collectionpropertiespage.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "collectionpropertiespage.h" - -using namespace Akonadi; - -/** - * @internal - */ -class CollectionPropertiesPage::Private -{ - public: - QString title; -}; - -CollectionPropertiesPage::CollectionPropertiesPage( QWidget *parent ) : - QWidget( parent ), - d( new Private ) -{ -} - -CollectionPropertiesPage::~CollectionPropertiesPage() -{ - delete d; -} - -bool CollectionPropertiesPage::canHandle(const Collection&) const -{ - return true; -} - -QString Akonadi::CollectionPropertiesPage::pageTitle() const -{ - return d->title; -} - -void CollectionPropertiesPage::setPageTitle(const QString & title) -{ - d->title = title; -} - -CollectionPropertiesPageFactory::~CollectionPropertiesPageFactory() -{ -} - -#include "collectionpropertiespage.moc" diff --git a/akonadi/collectionpropertiespage.h b/akonadi/collectionpropertiespage.h deleted file mode 100644 index c52809bbb..000000000 --- a/akonadi/collectionpropertiespage.h +++ /dev/null @@ -1,218 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_COLLECTIONPROPERTIESPAGE_H -#define AKONADI_COLLECTIONPROPERTIESPAGE_H - -#include "akonadi_export.h" - -#include - -namespace Akonadi { - -class Collection; - -/** - * @short A single page in a collection properties dialog. - * - * The collection properties dialog can be extended by custom - * collection properties pages, which provide gui elements for - * viewing and changing collection attributes. - * - * The following example shows how to create a simple collection - * properties page for the secercy attribute from the Akonadi::Attribute - * example. - * - * @code - * - * class SecrecyPage : public CollectionPropertiesPage - * { - * public: - * SecrecyPage( QWidget *parent = 0 ) - * : CollectionPropertiesPage( parent ) - * { - * QVBoxLayout *layout = new QVBoxLayout( this ); - * - * mSecrecy = new QComboBox( this ); - * mSecrecy->addItem( "Public" ); - * mSecrecy->addItem( "Private" ); - * mSecrecy->addItem( "Confidential" ); - * - * layout->addWidget( new QLabel( "Secrecy:" ) ); - * layout->addWidget( mSecrecy ); - * - * setPageTitle( i18n( "Secrecy" ) ); - * } - * - * void load( const Collection &collection ) - * { - * SecrecyAttribute *attr = collection.attribute( "secrecy" ); - * - * switch ( attr->secrecy() ) { - * case SecrecyAttribute::Public: mSecrecy->setCurrentIndex( 0 ); break; - * case SecrecyAttribute::Private: mSecrecy->setCurrentIndex( 1 ); break; - * case SecrecyAttribute::Confidential: mSecrecy->setCurrentIndex( 2 ); break; - * } - * } - * - * void save( Collection &collection ) - * { - * SecrecyAttribute *attr = collection.attribute( "secrecy" ); - * - * switch ( mSecrecy->currentIndex() ) { - * case 0: attr->setSecrecy( SecrecyAttribute::Public ); break; - * case 1: attr->setSecrecy( SecrecyAttribute::Private ); break; - * case 2: attr->setSecrecy( SecrecyAttribute::Confidential ); break; - * } - * } - * - * bool canHandle( const Collection &collection ) const - * { - * return collection.hasAttribute( "secrecy" ); - * } - * }; - * - * AKONADI_COLLECTION_PROPERTIES_PAGE_FACTORY( SecrecyPageFactory, SecrecyPage ) - * - * @endcode - * - * @see Akonadi::CollectionPropertiesDialog, Akonadi::CollectionPropertiesPageFactory - * - * @author Volker Krause - */ -class AKONADI_EXPORT CollectionPropertiesPage : public QWidget -{ - Q_OBJECT - public: - /** - * Creates a new collection properties page. - * - * @param parent The parent widget. - */ - explicit CollectionPropertiesPage( QWidget *parent = 0 ); - - /** - * Destroys the collection properties page. - */ - ~CollectionPropertiesPage(); - - /** - * Loads the page content from the given collection. - * - * @param collection The collection to load. - */ - virtual void load( const Collection &collection ) = 0; - - /** - * Saves page content to the given collection. - * - * @param collection Reference to the collection to save to. - */ - virtual void save( Collection &collection ) = 0; - - /** - * Checks if this page can actually handle the given collection. - * - * Returns @c true if the collection can be handled, @c false otherwise - * The default implementation returns always @c true. When @c false is returned - * this page is not shown in the properties dialog. - */ - virtual bool canHandle( const Collection &collection ) const; - - /** - * Sets the page title. - * - * @param title Translated, preferrably short tab title. - */ - void setPageTitle( const QString &title ); - - /** - * Returns the page title. - */ - QString pageTitle() const; - - private: - //@cond PRIVATE - class Private; - Private* const d; - //@endcond -}; - -/** - * @short A factory class for collection properties dialog pages. - * - * The factory encapsulates the creation of the collection properties - * dialog page. - * You can use the AKONADI_COLLECTION_PROPERTIES_PAGE_FACTORY macro - * to create a factory class automatically. - * - * @author Volker Krause - */ -class AKONADI_EXPORT CollectionPropertiesPageFactory -{ - public: - /** - * Destroys the collection properties page factory. - */ - virtual ~CollectionPropertiesPageFactory(); - - /** - * Returns the actual page widget. - * - * @param parent The parent widget. - */ - virtual CollectionPropertiesPage* createWidget( QWidget *parent = 0 ) const = 0; -}; - -/** - * @def AKONADI_COLLECTION_PROPERTIES_PAGE_FACTORY - * - * The AKONADI_COLLECTION_PROPERTIES_PAGE_FACTORY macro can be used to - * create a factory for a custom collection properties page. - * - * @code - * - * class MyPage : public Akonadi::CollectionPropertiesPage - * { - * ... - * } - * - * AKONADI_COLLECTION_PROPERTIES_PAGE_FACTORY( MyPageFactory, MyPage ) - * - * @endcode - * - * The macro takes two arguments, where the first one is the name of the - * factory class that shall be created and the second arguments is the name - * of the custom collection properties page class. - * - * @ingroup AkonadiMacros - */ -#define AKONADI_COLLECTION_PROPERTIES_PAGE_FACTORY(factoryName, className) \ -class factoryName: public CollectionPropertiesPageFactory \ -{ \ - public: \ - inline CollectionPropertiesPage* createWidget( QWidget *parent = 0 ) const \ - { \ - return new className( parent ); \ - } \ -}; - -} - -#endif diff --git a/akonadi/collectionrightsattribute.cpp b/akonadi/collectionrightsattribute.cpp deleted file mode 100644 index 1777ad23f..000000000 --- a/akonadi/collectionrightsattribute.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* - Copyright (c) 2007 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "collectionrightsattribute.h" - -using namespace Akonadi; - -static const char* s_accessRightsIdentifier = "AccessRights"; - -static Collection::Rights dataToRights( const QByteArray &data ) -{ - Collection::Rights rights = Collection::ReadOnly; - - if ( data.isEmpty() || data.at( 0 ) == 'a' ) - return Collection::AllRights; - - for ( int i = 0; i < data.count(); ++i ) { - switch ( data.at( i ) ) { - case 'w': rights |= Collection::CanChangeItem; break; - case 'c': rights |= Collection::CanCreateItem; break; - case 'd': rights |= Collection::CanDeleteItem; break; - case 'W': rights |= Collection::CanChangeCollection; break; - case 'C': rights |= Collection::CanCreateCollection; break; - case 'D': rights |= Collection::CanDeleteCollection; break; - } - } - - return rights; -} - -static QByteArray rightsToData( Collection::Rights &rights ) -{ - if ( rights == Collection::AllRights ) - return QByteArray( "a" ); - - QByteArray data; - if ( rights & Collection::CanChangeItem ) - data.append( 'w' ); - if ( rights & Collection::CanCreateItem ) - data.append( 'c' ); - if ( rights & Collection::CanDeleteItem ) - data.append( 'd' ); - if ( rights & Collection::CanChangeCollection ) - data.append( 'W' ); - if ( rights & Collection::CanCreateCollection ) - data.append( 'C' ); - if ( rights & Collection::CanDeleteCollection ) - data.append( 'D' ); - - return data; -} - -/** - * @internal - */ -class CollectionRightsAttribute::Private -{ - public: - QByteArray mData; -}; - -CollectionRightsAttribute::CollectionRightsAttribute() - : Attribute(), d( new Private ) -{ -} - -CollectionRightsAttribute::~CollectionRightsAttribute() -{ - delete d; -} - -void CollectionRightsAttribute::setRights( Collection::Rights rights ) -{ - d->mData = rightsToData( rights ); -} - -Collection::Rights CollectionRightsAttribute::rights() const -{ - return dataToRights( d->mData ); -} - -CollectionRightsAttribute* CollectionRightsAttribute::clone() const -{ - CollectionRightsAttribute *attr = new CollectionRightsAttribute(); - attr->d->mData = d->mData; - - return attr; -} - -QByteArray CollectionRightsAttribute::type() const -{ - return s_accessRightsIdentifier; -} - -QByteArray CollectionRightsAttribute::serialized() const -{ - return d->mData; -} - -void CollectionRightsAttribute::deserialize( const QByteArray &data ) -{ - d->mData = data; -} diff --git a/akonadi/collectionrightsattribute.h b/akonadi/collectionrightsattribute.h deleted file mode 100644 index 0035f4e79..000000000 --- a/akonadi/collectionrightsattribute.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - Copyright (c) 2007 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_COLLECTIONRIGHTSATTRIBUTE_H -#define AKONADI_COLLECTIONRIGHTSATTRIBUTE_H - -#include "akonadi_export.h" - -#include -#include - -namespace Akonadi { - -/** - * @short Attribute that stores the rights of a collection. - * - * Every collection can have rights set which describes whether - * the collection is readable or writable. That information is stored - * in this custom attribute. - * - * @note You shouldn't use this class directly but the convenience methods - * Collection::rights() and Collection::setRights() instead. - * - * @author Tobias Koenig - */ -class AKONADI_EXPORT CollectionRightsAttribute : public Attribute -{ - public: - /** - * Creates a new collection rights attribute. - */ - CollectionRightsAttribute(); - - /** - * Destroys the collection rights attribute. - */ - ~CollectionRightsAttribute(); - - /** - * Sets the @p rights of the collection. - */ - void setRights( Collection::Rights rights ); - - /** - * Returns the rights of the collection. - */ - Collection::Rights rights() const; - - virtual QByteArray type() const; - - virtual CollectionRightsAttribute* clone() const; - - virtual QByteArray serialized() const; - - virtual void deserialize( const QByteArray& ); - - private: - //@cond PRIVATE - class Private; - Private* const d; - //@endcond -}; - -} - -#endif diff --git a/akonadi/collectionselectjob.cpp b/akonadi/collectionselectjob.cpp deleted file mode 100644 index 1a413fab3..000000000 --- a/akonadi/collectionselectjob.cpp +++ /dev/null @@ -1,95 +0,0 @@ -/* - Copyright (c) 2006 - 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "collectionselectjob.h" - -#include "job_p.h" - -#include - -using namespace Akonadi; - -class Akonadi::CollectionSelectJobPrivate : public JobPrivate -{ - public: - CollectionSelectJobPrivate( CollectionSelectJob *parent ) - : JobPrivate( parent ), - mUnseen( -1 ), - mSilent( true ) - { - } - - Collection mCollection; - int mUnseen; - bool mSilent; -}; - -CollectionSelectJob::CollectionSelectJob( const Collection &collection, QObject *parent ) - : Job( new CollectionSelectJobPrivate( this ), parent ) -{ - Q_D( CollectionSelectJob ); - - d->mCollection = collection; -} - -CollectionSelectJob::~CollectionSelectJob( ) -{ -} - -void CollectionSelectJob::doStart( ) -{ - Q_D( CollectionSelectJob ); - - QByteArray command( d->newTag() + " SELECT " ); - if ( d->mSilent ) - command += "SILENT "; - d->writeData( command + QByteArray::number( d->mCollection.id() ) + '\n' ); -} - -void CollectionSelectJob::doHandleResponse( const QByteArray & tag, const QByteArray & data ) -{ - Q_D( CollectionSelectJob ); - - if ( tag == "*" ) { - if ( data.startsWith( "OK [UNSEEN" ) ) { - int begin = data.indexOf( ' ', 4 ); - int end = data.indexOf( ']' ); - QByteArray number = data.mid( begin + 1, end - begin - 1 ); - d->mUnseen = number.toInt(); - return; - } - } -} - -int CollectionSelectJob::unseen( ) const -{ - Q_D( const CollectionSelectJob ); - - return d->mUnseen; -} - -void CollectionSelectJob::setRetrieveStatus(bool status) -{ - Q_D( CollectionSelectJob ); - - d->mSilent = !status; -} - - -#include "collectionselectjob.moc" diff --git a/akonadi/collectionselectjob.h b/akonadi/collectionselectjob.h deleted file mode 100644 index 2300140d0..000000000 --- a/akonadi/collectionselectjob.h +++ /dev/null @@ -1,70 +0,0 @@ -/* - Copyright (c) 2006 - 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_COLLECTIONSELECTJOB_H -#define AKONADI_COLLECTIONSELECTJOB_H - -#include -#include - -namespace Akonadi { - -class CollectionSelectJobPrivate; - -/** - * @internal - * Selects a specific collection. See RFC 3501 for select semantics. - */ -class AKONADI_EXPORT CollectionSelectJob : public Job -{ - Q_OBJECT - public: - /** - Creates a new collection select job. - @param collection The collection to select. - @param parent The parent object. - */ - explicit CollectionSelectJob( const Collection &collection, QObject *parent = 0 ); - - /** - Destroys this job. - */ - virtual ~CollectionSelectJob(); - - /** - Enable fetching of collection status details. - */ - void setRetrieveStatus( bool status ); - - /** - Returns the unseen count of the selected folder, -1 if not available. - */ - int unseen() const; - - protected: - void doStart(); - void doHandleResponse( const QByteArray &tag, const QByteArray &data ); - - private: - Q_DECLARE_PRIVATE( CollectionSelectJob ) -}; - -} - -#endif diff --git a/akonadi/collectionstatistics.cpp b/akonadi/collectionstatistics.cpp deleted file mode 100644 index d8683b7be..000000000 --- a/akonadi/collectionstatistics.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "collectionstatistics.h" - -#include - -using namespace Akonadi; - -/** - * @internal - */ -class CollectionStatistics::Private : public QSharedData -{ - public: - Private() : - QSharedData(), - count( -1 ), - unreadCount( -1 ) - {} - - Private( const Private &other ) : - QSharedData( other ) - { - count = other.count; - unreadCount = other.count; - } - - qint64 count; - qint64 unreadCount; -}; - - -CollectionStatistics::CollectionStatistics() : - d( new Private ) -{ -} - -CollectionStatistics::CollectionStatistics(const CollectionStatistics &other) : - d( other.d ) -{ -} - -CollectionStatistics::~CollectionStatistics() -{ -} - -qint64 CollectionStatistics::count( ) const -{ - return d->count; -} - -void CollectionStatistics::setCount( qint64 count ) -{ - d->count = count; -} - -qint64 CollectionStatistics::unreadCount( ) const -{ - return d->unreadCount; -} - -void CollectionStatistics::setUnreadCount( qint64 count ) -{ - d->unreadCount = count; -} - -CollectionStatistics& CollectionStatistics::operator =(const CollectionStatistics & other) -{ - d = other.d; - return *this; -} diff --git a/akonadi/collectionstatistics.h b/akonadi/collectionstatistics.h deleted file mode 100644 index a3bac2111..000000000 --- a/akonadi/collectionstatistics.h +++ /dev/null @@ -1,125 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_COLLECTIONSTATISTICS_H -#define AKONADI_COLLECTIONSTATISTICS_H - -#include "akonadi_export.h" -#include -#include - -namespace Akonadi { - -/** - * @short Provides statistics information of a Collection. - * - * This class contains information such as total number of items, - * number of new and unread items, etc. - * - * These information might be expensive to obtain and are thus - * not included when fetching collection with a CollectionFetchJob. - * They can be retrieved spearately using CollectionStatisticsJob. - * - * Example: - * - * @code - * - * Akonadi::Collection collection = ... - * - * Akonadi::CollectionStatisticsJob *job = new Akonadi::CollectionStatisticsJob( collection ); - * if ( job->exec() ) { - * Akonadi::CollectionStatistics statistics = job->statistics(); - * qDebug() << "Unread items:" << statistics.unreadCount(); - * } - * - * @endcode - * - * This class is implicitely shared. - * - * @author Volker Krause - */ -class AKONADI_EXPORT CollectionStatistics -{ - public: - /** - * Creates a new collection statistics object. - */ - CollectionStatistics(); - - /** - * Creates a collection statistics object from an @p other one. - */ - CollectionStatistics( const CollectionStatistics &other ); - - /** - * Destroys the collection statistics object. - */ - ~CollectionStatistics(); - - /** - * Returns the number of items in this collection or @c -1 if - * this information is not available. - * - * @see setCount() - * @see unreadCount() - */ - qint64 count() const; - - /** - * Sets the number of items in this collection. - * - * @param count The number of items. - * @see count() - */ - void setCount( qint64 count ); - - /** - * Returns the number of unread items in this collection or @c -1 if - * this information is not available. - * - * @see setUnreadCount() - * @see count() - */ - qint64 unreadCount() const; - - /** - * Sets the number of unread items in this collection. - * - * @param count The number of unread messages. - * @see unreadCount() - */ - void setUnreadCount( qint64 count ); - - /** - * Assigns @p other to this statistics object and returns a reference to this one. - */ - CollectionStatistics& operator=( const CollectionStatistics &other ); - - private: - //@cond PRIVATE - class Private; - QSharedDataPointer d; - //@endcond -}; - -} - -Q_DECLARE_METATYPE( Akonadi::CollectionStatistics ) - -#endif diff --git a/akonadi/collectionstatisticsdelegate.cpp b/akonadi/collectionstatisticsdelegate.cpp deleted file mode 100644 index 15b78a211..000000000 --- a/akonadi/collectionstatisticsdelegate.cpp +++ /dev/null @@ -1,210 +0,0 @@ -/* - Copyright (c) 2008 Thomas McGuire - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "collectionstatisticsdelegate.h" -#include "collectionstatisticsmodel.h" - -#include -#include - -#include -#include -#include -#include -#include - -using namespace Akonadi; - -namespace Akonadi { - -class CollectionStatisticsDelegatePrivate -{ - public: - QTreeView *parent; - bool drawUnreadAfterFolder; - - CollectionStatisticsDelegatePrivate( QTreeView *treeView ) - : parent( treeView ), drawUnreadAfterFolder( false ) - { - } -}; - -} - -CollectionStatisticsDelegate::CollectionStatisticsDelegate( QTreeView *parent ) - : QStyledItemDelegate( parent ), - d_ptr( new CollectionStatisticsDelegatePrivate( parent ) ) -{ -} - -CollectionStatisticsDelegate::~CollectionStatisticsDelegate() -{ - delete d_ptr; -} - -void CollectionStatisticsDelegate::setUnreadCountShown( bool enable ) -{ - Q_D( CollectionStatisticsDelegate ); - d->drawUnreadAfterFolder = enable; -} - -bool CollectionStatisticsDelegate::unreadCountShown() const -{ - Q_D( const CollectionStatisticsDelegate ); - return d->drawUnreadAfterFolder; -} - -void CollectionStatisticsDelegate::initStyleOption( QStyleOptionViewItem *option, - const QModelIndex &index ) const -{ - QStyleOptionViewItemV4 *noTextOption = - qstyleoption_cast( option ); - QStyledItemDelegate::initStyleOption( noTextOption, index ); - noTextOption->text.clear(); -} - -void CollectionStatisticsDelegate::paint( QPainter *painter, - const QStyleOptionViewItem &option, - const QModelIndex &index ) const -{ - Q_D( const CollectionStatisticsDelegate ); - - // First, paint the basic, but without the text. We remove the text - // in initStyleOption(), which gets called by QStyledItemDelegate::paint(). - QStyledItemDelegate::paint( painter, option, index ); - - // No, we retrieve the correct style option by calling intiStyleOption from - // the superclass. - QStyleOptionViewItemV4 option4 = option; - QStyledItemDelegate::initStyleOption( &option4, index ); - QString text = option4.text; - - // Now calculate the rectangle for the text - QStyle *s = d->parent->style(); - const QWidget *widget = option4.widget; - QRect textRect = s->subElementRect( QStyle::SE_ItemViewItemText, &option4, widget ); - - // When checking if the item is expanded, we need to check that for the first - // column, as Qt only recogises the index as expanded for the first column - QModelIndex firstColumn = index.model()->index( index.row(), 0, index.parent() ); - bool expanded = d->parent->isExpanded( firstColumn ); - - // Draw the unread count after the folder name (in parenthesis) - if ( d->drawUnreadAfterFolder && index.column() == 0 ) { - - QVariant unreadCount = index.model()->data( index, - CollectionStatisticsModel::UnreadRole ); - QVariant unreadRecursiveCount = index.model()->data( index, - CollectionStatisticsModel::RecursiveUnreadRole ); - Q_ASSERT( unreadCount.type() == QVariant::LongLong ); - Q_ASSERT( unreadRecursiveCount.type() == QVariant::LongLong ); - - // Construct the string which will appear after the foldername (with the - // unread count) - QString unread; - QString unreadCountInChilds = QString::number( unreadRecursiveCount.toLongLong() - - unreadCount.toLongLong() ); - if ( expanded && unreadCount.toLongLong() > 0 ) - unread = QString( QLatin1String(" (%1)") ).arg( unreadCount.toLongLong() ); - else if ( !expanded ) { - if ( unreadCount.toLongLong() != unreadRecursiveCount.toLongLong() ) - unread = QString( QLatin1String(" (%1 + %2)") ).arg( unreadCount.toString(), - unreadCountInChilds ); - else if ( unreadCount.toLongLong() > 0 ) - unread = QString( QLatin1String(" (%1)") ).arg( unreadCount.toString() ); - } - - painter->save(); - - if ( !unread.isEmpty() ) { - QFont font = painter->font(); - font.setBold( true ); - painter->setFont( font ); - } - - // Squeeze the folder text if it is to big and calculate the rectangles - // where the folder text and the unread count will be drawn to - QString folderName = text; - QFontMetrics fm( painter->fontMetrics() ); - int unreadWidth = fm.width( unread ); - if ( fm.width( folderName ) + unreadWidth > textRect.width() ) { - folderName = fm.elidedText( folderName, Qt::ElideRight, - textRect.width() - unreadWidth ); - } - int folderWidth = fm.width( folderName ); - QRect folderRect = textRect; - QRect unreadRect = textRect; - folderRect.setRight( textRect.left() + folderWidth ); - unreadRect.setLeft( folderRect.right() ); - - // Draw folder name and unread count - painter->drawText( folderRect, Qt::AlignLeft, folderName ); - KColorScheme::ColorSet cs = ( option.state & QStyle::State_Selected ) ? - KColorScheme::Selection : KColorScheme::View; - QColor unreadColor = KColorScheme( QPalette::Active, cs ). - foreground( KColorScheme::LinkText ).color(); - painter->setPen( unreadColor ); - painter->drawText( unreadRect, Qt::AlignLeft, unread ); - painter->restore(); - return; - } - - // For the unread/total column, paint the summed up count if the item - // is collapsed - if ( ( index.column() == 1 || index.column() == 2 ) ) { - - painter->save(); - - int role = 0; - if ( index.column() == 1 ) { - if ( !expanded ) - role = CollectionStatisticsModel::RecursiveUnreadRole; - else - role = CollectionStatisticsModel::UnreadRole; - } - else if ( index.column() == 2 ) { - if ( !expanded ) - role = CollectionStatisticsModel::RecursiveTotalRole; - else - role = CollectionStatisticsModel::TotalRole; - } - - QVariant sum = index.model()->data( index, role ); - Q_ASSERT( sum.type() == QVariant::LongLong ); - QStyleOptionViewItem opt = option; - if ( index.column() == 1 && sum.toLongLong() > 0 ) { - QFont font = painter->font(); - font.setBold( true ); - painter->setFont( font ); - } - QString sumText; - if ( sum.toLongLong() <= 0 ) - sumText = text; - else - sumText = sum.toString(); - - painter->drawText( textRect, Qt::AlignRight, sumText ); - painter->restore(); - return; - } - - painter->drawText( textRect, option4.displayAlignment, text ); -} - -#include "collectionstatisticsdelegate.moc" diff --git a/akonadi/collectionstatisticsdelegate.h b/akonadi/collectionstatisticsdelegate.h deleted file mode 100644 index 6a212c858..000000000 --- a/akonadi/collectionstatisticsdelegate.h +++ /dev/null @@ -1,111 +0,0 @@ -/* - Copyright (c) 2008 Thomas McGuire - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ -#ifndef AKONADI_COLLECTIONSTATISTICSDELEGATE_H -#define AKONADI_COLLECTIONSTATISTICSDELEGATE_H - -#include "akonadi_export.h" - -#include - -class QTreeView; - -namespace Akonadi { - -class CollectionStatisticsDelegatePrivate; - -/** - * @short A delegate that draws unread and total count for CollectionStatisticsModel. - * - * The delegate provides the following features: - * - * - Collections with unread items will have the foldername and the unread - * column marked in bold. - * - If a folder is collapsed, the unread and the total column will contain - * the total sum of all child folders - * - It has the possibility to draw the unread count directly after the - * foldername, see toggleUnreadAfterFolderName(). - * - * Example: - * @code - * - * QTreeView *view = new QTreeView( this ); - * - * Akonadi::CollectionStatisticsModel *model = new Akonadi::CollectionStatisticsModel( view ); - * view->setModel( model ); - * - * Akonadi::CollectionStatisticsDelegate *delegate = new Akonadi::CollectionStatisticsDelegate( view ); - * view->setItemDelegate( delegate ); - * - * @endcode - * - * @author Thomas McGuire - */ -class AKONADI_EXPORT CollectionStatisticsDelegate : public QStyledItemDelegate -{ - Q_OBJECT - - public: - - /** - * Creates a new collection statistics delegate. - * - * @param parent The parent tree view, which will also take ownership. - */ - explicit CollectionStatisticsDelegate( QTreeView *parent ); - - /** - * Destroys the collection statistics delegate. - */ - ~CollectionStatisticsDelegate(); - - public Q_SLOTS: - /** - * Sets whether the unread count is drawn next to the folder name. - * - * You probably want to enable this when the unread count is hidden only. - * This is disabled by default. - * - * @param enable If @c true, the unread count is drawn next to the folder name, - * if @c false, the folder name will be drawn normally. - */ - void setUnreadCountShown( bool enable ); - - /** - * Returns whether the unread count is drawn next to the folder name. - */ - bool unreadCountShown() const; - - protected: - virtual void paint( QPainter *painter, const QStyleOptionViewItem &option, - const QModelIndex &index ) const; - - virtual void initStyleOption( QStyleOptionViewItem *option, - const QModelIndex &index ) const; - - private: - //@cond PRIVATE - CollectionStatisticsDelegatePrivate* const d_ptr; - //@endcond - - Q_DECLARE_PRIVATE( CollectionStatisticsDelegate ) -}; - -} - -#endif diff --git a/akonadi/collectionstatisticsjob.cpp b/akonadi/collectionstatisticsjob.cpp deleted file mode 100644 index ea7fc1c68..000000000 --- a/akonadi/collectionstatisticsjob.cpp +++ /dev/null @@ -1,106 +0,0 @@ -/* - Copyright (c) 2006 - 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "collectionstatisticsjob.h" - -#include "collection.h" -#include "collectionstatistics.h" -#include "imapparser_p.h" -#include "job_p.h" - -#include - -using namespace Akonadi; - -class Akonadi::CollectionStatisticsJobPrivate : public JobPrivate -{ - public: - CollectionStatisticsJobPrivate( CollectionStatisticsJob *parent ) - : JobPrivate( parent ) - { - } - - Collection mCollection; - CollectionStatistics mStatistics; -}; - -CollectionStatisticsJob::CollectionStatisticsJob( const Collection &collection, QObject * parent ) - : Job( new CollectionStatisticsJobPrivate( this ), parent ) -{ - Q_D( CollectionStatisticsJob ); - - d->mCollection = collection; -} - -CollectionStatisticsJob::~CollectionStatisticsJob() -{ -} - -void CollectionStatisticsJob::doStart( ) -{ - Q_D( CollectionStatisticsJob ); - - d->writeData( d->newTag() + " STATUS " + QByteArray::number( d->mCollection.id() ) + " (MESSAGES UNSEEN)\n" ); -} - -void CollectionStatisticsJob::doHandleResponse( const QByteArray & tag, const QByteArray & data ) -{ - Q_D( CollectionStatisticsJob ); - - if ( tag == "*" ) { - QByteArray token; - int current = ImapParser::parseString( data, token ); - if ( token == "STATUS" ) { - // folder path - current = ImapParser::parseString( data, token, current ); - // result list - QList list; - current = ImapParser::parseParenthesizedList( data, list, current ); - for ( int i = 0; i < list.count() - 1; i += 2 ) { - if ( list[i] == "MESSAGES" ) { - d->mStatistics.setCount( list[i+1].toLongLong() ); - } else if ( list[i] == "UNSEEN" ) { - d->mStatistics.setUnreadCount( list[i+1].toLongLong() ); - } else { - kDebug( 5250 ) << "Unknown STATUS response: " << list[i]; - } - } - - d->mCollection.setStatistics( d->mStatistics ); - return; - } - } - kDebug( 5250 ) << "Unhandled response: " << tag << data; -} - -Collection CollectionStatisticsJob::collection() const -{ - Q_D( const CollectionStatisticsJob ); - - return d->mCollection; -} - -CollectionStatistics Akonadi::CollectionStatisticsJob::statistics() const -{ - Q_D( const CollectionStatisticsJob ); - - return d->mStatistics; -} - -#include "collectionstatisticsjob.moc" diff --git a/akonadi/collectionstatisticsjob.h b/akonadi/collectionstatisticsjob.h deleted file mode 100644 index 40e516398..000000000 --- a/akonadi/collectionstatisticsjob.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - Copyright (c) 2006 - 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_COLLECTIONSTATISTICSJOB_H -#define AKONADI_COLLECTIONSTATISTICSJOB_H - -#include "akonadi_export.h" - -#include - -namespace Akonadi { - -class Collection; -class CollectionStatistics; -class CollectionStatisticsJobPrivate; - -/** - * @short Job that fetches collection statistics from the Akonadi storage. - * - * This class fetches the CollectionStatistics object for a given collection. - * - * Example: - * - * @code - * - * Akonadi::Collection collection = ... - * - * Akonadi::CollectionStatisticsJob *job = new Akonadi::CollectionStatisticsJob( collection ); - * if ( job->exec() ) { - * Akonadi::CollectionStatistics statistics = job->statistics(); - * qDebug() << "Unread items:" << statistics.unreadCount(); - * } - * - * @endcode - * - * @author Volker Krause - */ -class AKONADI_EXPORT CollectionStatisticsJob : public Job -{ - Q_OBJECT - - public: - /** - * Creates a new collection statistics job. - * - * @param collection The collection to fetch the statistics from. - * @param parent The parent object. - */ - explicit CollectionStatisticsJob( const Collection &collection, QObject *parent = 0 ); - - /** - * Destroys the collection statistics job. - */ - virtual ~CollectionStatisticsJob(); - - /** - * Returns the fetched collection statistics. - */ - CollectionStatistics statistics() const; - - /** - * Returns the corresponding collection, if the job was executed successfully, - * the collection is already updated. - */ - Collection collection() const; - - protected: - virtual void doStart(); - virtual void doHandleResponse( const QByteArray &tag, const QByteArray &data ); - - private: - Q_DECLARE_PRIVATE( CollectionStatisticsJob ) -}; - -} - -#endif diff --git a/akonadi/collectionstatisticsmodel.cpp b/akonadi/collectionstatisticsmodel.cpp deleted file mode 100644 index d3729f58a..000000000 --- a/akonadi/collectionstatisticsmodel.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "collectionstatisticsmodel.h" - -#include "collection.h" -#include "collectionmodel_p.h" -#include "collectionstatistics.h" - -#include -#include - -#include - -using namespace Akonadi; - -namespace Akonadi { - -class CollectionStatisticsModelPrivate : public CollectionModelPrivate -{ - public: - enum CountType { Total, Unread }; - Q_DECLARE_PUBLIC( CollectionStatisticsModel ) - CollectionStatisticsModelPrivate( CollectionStatisticsModel *parent ) - : CollectionModelPrivate( parent ) - {} - - qint64 countRecursive( Collection::Id collection, CountType type ) const; -}; - -} - -qint64 CollectionStatisticsModelPrivate::countRecursive( Collection::Id collection, - CountType type ) const -{ - qint64 result = -1; - switch ( type ) { - case Unread: result = collections.value( collection ).statistics().unreadCount(); - break; - case Total: result = collections.value( collection ).statistics().count(); - break; - default: Q_ASSERT( false ); - break; - } - - QList children = childCollections.value( collection ); - foreach( Collection::Id currentCollection, children ) { - result += countRecursive( currentCollection, type ); - } - return result; -} - -CollectionStatisticsModel::CollectionStatisticsModel( QObject * parent ) : - CollectionModel( new CollectionStatisticsModelPrivate( this ), parent ) -{ - fetchCollectionStatistics( true ); -} - -int CollectionStatisticsModel::columnCount( const QModelIndex & parent ) const -{ - if ( parent.isValid() && parent.column() != 0 ) - return 0; - return 3; -} - -QVariant CollectionStatisticsModel::data( const QModelIndex & index, int role ) const -{ - Q_D( const CollectionStatisticsModel ); - if ( !index.isValid() ) - return QVariant(); - - Collection col = collectionForId( CollectionModel::data( index, CollectionIdRole ).toLongLong() ); - if ( !col.isValid() ) - return QVariant(); - CollectionStatistics statistics = col.statistics(); - - qint64 total = statistics.count(); - qint64 unread = statistics.unreadCount(); - qint64 totalRecursive = d->countRecursive( col.id(), - CollectionStatisticsModelPrivate::Total ); - qint64 unreadRecursive = d->countRecursive( col.id(), - CollectionStatisticsModelPrivate::Unread ); - - if ( role == TotalRole ) - return total; - else if ( role == UnreadRole ) - return unread; - else if ( role == RecursiveUnreadRole ) - return unreadRecursive; - else if ( role == RecursiveTotalRole ) - return totalRecursive; - else if ( role == StatisticsRole ) { - QVariant var; - var.setValue( statistics ); - return var; - } else if ( role == RecursiveStatisticsRole ) { - QVariant var; - var.setValue( statistics ); //FIXME:(tmg) returns a recursive statistic object here - return var; - } - - if ( role == Qt::DisplayRole && - ( index.column() == 1 || index.column() == 2 ) ) { - - qint64 value = -1; - switch ( index.column() ) { - case 1 : value = unread; break; - case 2 : value = total; break; - } - if ( value < 0 ) - return QString(); - else if ( value == 0 ) - return QLatin1String( "-" ); - else - return QString::number( value ); - } - - if ( role == Qt::TextAlignmentRole && ( index.column() == 1 || index.column() == 2 ) ) - return Qt::AlignRight; - - return CollectionModel::data( index, role ); -} - -QVariant CollectionStatisticsModel::headerData( int section, Qt::Orientation orientation, int role ) const -{ - if ( orientation == Qt::Horizontal && role == Qt::DisplayRole ) - switch ( section ) { - case 1: return i18nc( "@title:column, number of unread messages", "Unread" ); - case 2: return i18nc( "@title:column, total number of messages", "Total" ); - } - - return CollectionModel::headerData( section, orientation, role ); -} - -#include "collectionstatisticsmodel.moc" diff --git a/akonadi/collectionstatisticsmodel.h b/akonadi/collectionstatisticsmodel.h deleted file mode 100644 index b3f4ce408..000000000 --- a/akonadi/collectionstatisticsmodel.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_COLLECTIONSTATISTICSMODEL_H -#define AKONADI_COLLECTIONSTATISTICSMODEL_H - -#include "akonadi_export.h" -#include - -namespace Akonadi { - -class CollectionStatisticsModelPrivate; - -/** - * @short A model that provides statistics for collections. - * - * This model extends the CollectionModel by providing additional - * information about the collections, e.g. the number of items - * in a collection or the number of read/unread items. - * - * Example: - * - * @code - * - * QTreeView *view = new QTreeView( this ); - * - * Akonadi::CollectionStatisticsModel *model = new Akonadi::CollectionStatisticsModel( view ); - * view->setModel( model ); - * - * @endcode - * - * @author Volker Krause - */ -class AKONADI_EXPORT CollectionStatisticsModel : public CollectionModel -{ - Q_OBJECT - - public: - - /** - * Describes the roles for the statistics collection model. - */ - enum Roles { - UnreadRole = CollectionModel::UserRole + 1, ///< The number of unread items in this collection. - TotalRole, ///< The number of items in this collection. - StatisticsRole, ///< A statistics object of this collection. - RecursiveUnreadRole, ///< The number of unread items in this collection and its children. - RecursiveTotalRole, ///< The number of items in this collection and its children. - RecursiveStatisticsRole, ///< A statistics object of this collection and its children. - UserRole = CollectionModel::UserRole + 42 ///< Role for user extensions. - }; - - /** - * Creates a new collection statistics model. - * @param parent The parent object. - */ - explicit CollectionStatisticsModel( QObject *parent = 0 ); - - virtual int columnCount( const QModelIndex & parent = QModelIndex() ) const; - - virtual QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) const; - - virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; - - private: - Q_DECLARE_PRIVATE( CollectionStatisticsModel ) -}; - -} - -#endif diff --git a/akonadi/collectionsync.cpp b/akonadi/collectionsync.cpp deleted file mode 100644 index f5c7dec0e..000000000 --- a/akonadi/collectionsync.cpp +++ /dev/null @@ -1,221 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "collectionsync.h" -#include "collection.h" - -#include "collectioncreatejob.h" -#include "collectiondeletejob.h" -#include "collectionfetchjob.h" -#include "collectionmodifyjob.h" - - -#include - -using namespace Akonadi; - -/** - * @internal - */ -class CollectionSync::Private -{ - public: - Private() : - pendingJobs( 0 ), - incremental( false ) - { - } - - QString resourceId; - - // local: mapped remote id -> collection, id -> collection - QHash localCollections; - QSet unprocessedLocalCollections; - - // remote: mapped id -> collection - QHash remoteCollections; - - // remote collections waiting for a parent - QList orphanRemoteCollections; - - // removed remote collections - Collection::List removedRemoteCollections; - - // create counter - int pendingJobs; - - bool incremental; -}; - -CollectionSync::CollectionSync( const QString &resourceId, QObject *parent ) : - TransactionSequence( parent ), - d( new Private ) -{ - d->resourceId = resourceId; -} - -CollectionSync::~CollectionSync() -{ - delete d; -} - -void CollectionSync::setRemoteCollections(const Collection::List & remoteCollections) -{ - foreach ( const Collection &c, remoteCollections ) { - d->remoteCollections.insert( c.id(), c ); - } -} - -void CollectionSync::setRemoteCollections(const Collection::List & changedCollections, const Collection::List & removedCollections) -{ - d->incremental = true; - foreach ( const Collection &c, changedCollections ) { - d->remoteCollections.insert( c.id(), c ); - } - d->removedRemoteCollections = removedCollections; -} - -void CollectionSync::doStart() -{ - CollectionFetchJob *job = new CollectionFetchJob( Collection::root(), CollectionFetchJob::Recursive, this ); - job->setResource( d->resourceId ); - connect( job, SIGNAL(result(KJob*)), SLOT(slotLocalListDone(KJob*)) ); -} - -void CollectionSync::slotLocalListDone(KJob * job) -{ - if ( job->error() ) - return; - - Collection::List list = static_cast( job )->collections(); - foreach ( const Collection &c, list ) { - d->localCollections.insert( c.remoteId(), c ); - d->unprocessedLocalCollections.insert( c ); - } - - - // added / updated - foreach ( const Collection &c, d->remoteCollections ) { - if ( c.remoteId().isEmpty() ) { - kWarning( 5250 ) << "Collection '" << c.name() <<"' does not have a remote identifier - skipping"; - continue; - } - - Collection local = d->localCollections.value( c.remoteId() ); - d->unprocessedLocalCollections.remove( local ); - // missing locally - if ( !local.isValid() ) { - // determine local parent - Collection localParent; - if ( c.parent() >= 0 ) - localParent = Collection( c.parent() ); - if ( c.parentRemoteId().isEmpty() ) - localParent = Collection::root(); - else - localParent = d->localCollections.value( c.parentRemoteId() ); - - // no local parent found, create later - if ( !localParent.isValid() ) { - d->orphanRemoteCollections << c; - continue; - } - - createLocalCollection( c, localParent ); - continue; - } - - // update local collection - d->pendingJobs++; - Collection upd( c ); - upd.setId( local.id() ); - CollectionModifyJob *mod = new CollectionModifyJob( upd, this ); - connect( mod, SIGNAL(result(KJob*)), SLOT(slotLocalChangeDone(KJob*)) ); - } - - // removed - if ( !d->incremental ) - d->removedRemoteCollections = d->unprocessedLocalCollections.toList(); - foreach ( const Collection &c, d->removedRemoteCollections ) { - d->pendingJobs++; - CollectionDeleteJob *job = new CollectionDeleteJob( c, this ); - connect( job, SIGNAL(result(KJob*)), SLOT(slotLocalChangeDone(KJob*)) ); - } - d->localCollections.clear(); - - checkDone(); -} - -void CollectionSync::slotLocalCreateDone(KJob * job) -{ - d->pendingJobs--; - if ( job->error() ) - return; - - Collection newLocal = static_cast( job )->collection(); -// d->localCollections.insert( newLocal.remoteId(), newLocal ); - - // search for children we can create now - Collection::List stillOrphans; - foreach ( const Collection &orphan, d->orphanRemoteCollections ) { - if ( orphan.parentRemoteId() == newLocal.remoteId() ) { - createLocalCollection( orphan, newLocal ); - } else { - stillOrphans << orphan; - } - } - d->orphanRemoteCollections = stillOrphans; - - checkDone(); -} - -void CollectionSync::createLocalCollection(const Collection & c, const Collection & parent) -{ - d->pendingJobs++; - Collection col( c ); - col.setParent( parent ); - CollectionCreateJob *create = new CollectionCreateJob( col, this ); - connect( create, SIGNAL(result(KJob*)), SLOT(slotLocalCreateDone(KJob*)) ); -} - -void CollectionSync::checkDone() -{ - // still running jobs - if ( d->pendingJobs > 0 ) - return; - - // still orphan collections - if ( !d->orphanRemoteCollections.isEmpty() ) { - setError( Unknown ); - setErrorText( QLatin1String( "Found unresolved orphan collections" ) ); - foreach ( const Collection &col, d->orphanRemoteCollections ) - kDebug() << "found orphan collection:" << col.remoteId() << "parent:" << col.parentRemoteId(); - } - - commit(); -} - -void CollectionSync::slotLocalChangeDone(KJob * job) -{ - if ( job->error() ) - return; - d->pendingJobs--; - checkDone(); -} - -#include "collectionsync.moc" diff --git a/akonadi/collectionsync.h b/akonadi/collectionsync.h deleted file mode 100644 index afedea62d..000000000 --- a/akonadi/collectionsync.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_COLLECTIONSYNC_H -#define AKONADI_COLLECTIONSYNC_H - -#include -#include - -namespace Akonadi { - -/** - @internal - - Syncs remote and local collections. -*/ -class CollectionSync : public TransactionSequence -{ - Q_OBJECT - - public: - /** - Creates a new collection synchronzier. - @param resourceId The identifier of the resource we are syncing. - @param parent The parent object. - */ - explicit CollectionSync( const QString &resourceId, QObject *parent = 0 ); - - /** - Destroys this job. - */ - ~CollectionSync(); - - /** - Sets the result of a full remote collection listing. - @param remoteCollections A list of collections. - Important: All of these need a unique remote identifier and parent remote - identifier. - */ - void setRemoteCollections( const Collection::List &remoteCollections ); - - /** - Sets the result of an incremental remote collection listing. - @param changedCollections A list of remotely added or changed collections. - @param removedCollections A lost of remotely deleted collections. - */ - void setRemoteCollections( const Collection::List &changedCollections, - const Collection::List &removedCollections ); - - protected: - void doStart(); - - private: - void createLocalCollection( const Collection &c, const Collection &parent ); - void checkDone(); - - private Q_SLOTS: - void slotLocalListDone( KJob *job ); - void slotLocalCreateDone( KJob *job ); - void slotLocalChangeDone( KJob *job ); - - private: - class Private; - Private* const d; -}; - -} - -#endif diff --git a/akonadi/collectionutils_p.h b/akonadi/collectionutils_p.h deleted file mode 100644 index 53f8e554d..000000000 --- a/akonadi/collectionutils_p.h +++ /dev/null @@ -1,90 +0,0 @@ -/* - Copyright (c) 2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_COLLECTIONUTILS_P_H -#define AKONADI_COLLECTIONUTILS_P_H - -#include - -namespace Akonadi { - -/** - * @internal - */ -namespace CollectionUtils -{ - inline bool isVirtualParent( const Collection &collection ) - { - return (collection.parent() == Collection::root().id() && - collection.resource() == QLatin1String( "akonadi_search_resource" )); - } - - inline bool isVirtual( const Collection &collection ) - { - return (collection.resource() == QLatin1String( "akonadi_search_resource" )); - } - - inline bool isResource( const Collection &collection ) - { - return (collection.parent() == Collection::root().id()); - } - - inline bool isStructural( const Collection &collection ) - { - return collection.contentMimeTypes().isEmpty(); - } - - inline bool isFolder( const Collection &collection ) - { - return (collection.parent() != Collection::root().id() && - collection.resource() != QLatin1String( "akonadi_search_resource" ) && - !collection.contentMimeTypes().isEmpty()); - } - - inline QString defaultIconName( const Collection &col ) - { - if ( CollectionUtils::isVirtualParent( col ) ) - return QLatin1String( "edit-find" ); - if ( CollectionUtils::isVirtual( col ) ) - return QLatin1String( "document-preview" ); - if ( CollectionUtils::isResource( col ) ) - return QLatin1String( "network-server" ); - if ( CollectionUtils::isStructural( col ) ) - return QLatin1String( "folder-grey" ); - - const QStringList content = col.contentMimeTypes(); - if ( content.size() == 1 || (content.size() == 2 && content.contains( Collection::mimeType() )) ) { - if ( content.contains( QLatin1String( "text/x-vcard" ) ) || content.contains( QLatin1String( "text/directory" ) ) - || content.contains( QLatin1String( "text/vcard" ) ) ) - return QLatin1String( "x-office-address-book" ); - // TODO: add all other content types and/or fix their mimetypes - if ( content.contains( QLatin1String( "akonadi/event" ) ) || content.contains( QLatin1String( "text/ical" ) ) ) - return QLatin1String( "view-pim-calendar" ); - if ( content.contains( QLatin1String( "akonadi/task" ) ) ) - return QLatin1String( "view-pim-tasks" ); - } else if ( content.isEmpty() ) { - return QLatin1String( "folder-grey" ); - } - return QLatin1String( "folder" ); - } -} - -} - -#endif diff --git a/akonadi/collectionview.cpp b/akonadi/collectionview.cpp deleted file mode 100644 index cfa0e3819..000000000 --- a/akonadi/collectionview.cpp +++ /dev/null @@ -1,248 +0,0 @@ -/* - Copyright (c) 2006 - 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "collectionview.h" - -#include "collection.h" -#include "collectionmodel.h" - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -using namespace Akonadi; - -/** - * @internal - */ -class CollectionView::Private -{ - public: - Private( CollectionView *parent ) - : mParent( parent ), - xmlGuiWindow( 0 ) - { - } - - void init(); - void dragExpand(); - void itemClicked( const QModelIndex& ); - void itemCurrentChanged( const QModelIndex& ); - bool hasParent( const QModelIndex& idx, Collection::Id parentId ); - - CollectionView *mParent; - QModelIndex dragOverIndex; - QTimer dragExpandTimer; - - KXmlGuiWindow *xmlGuiWindow; -}; - -void CollectionView::Private::init() -{ - mParent->header()->setClickable( true ); - mParent->header()->setStretchLastSection( false ); - - mParent->setSortingEnabled( true ); - mParent->sortByColumn( 0, Qt::AscendingOrder ); - mParent->setEditTriggers( QAbstractItemView::EditKeyPressed ); - mParent->setAcceptDrops( true ); - mParent->setDropIndicatorShown( true ); - mParent->setDragDropMode( DragDrop ); - mParent->setDragEnabled( true ); - - dragExpandTimer.setSingleShot( true ); - mParent->connect( &dragExpandTimer, SIGNAL(timeout()), SLOT(dragExpand()) ); - - mParent->connect( mParent, SIGNAL( clicked( const QModelIndex& ) ), - mParent, SLOT( itemClicked( const QModelIndex& ) ) ); -} - -bool CollectionView::Private::hasParent( const QModelIndex& idx, Collection::Id parentId ) -{ - QModelIndex idx2 = idx; - while( idx2.isValid() ) { - if ( mParent->model()->data( idx2, CollectionModel::CollectionIdRole).toLongLong() == parentId ) - return true; - - idx2 = idx2.parent(); - } - return false; -} - -void CollectionView::Private::dragExpand() -{ - mParent->setExpanded( dragOverIndex, true ); - dragOverIndex = QModelIndex(); -} - -void CollectionView::Private::itemClicked( const QModelIndex &index ) -{ - if ( !index.isValid() ) - return; - - const Collection col = index.model()->data( index, CollectionModel::CollectionRole ).value(); - if ( !col.isValid() ) - return; - - emit mParent->clicked( col ); -} - -void CollectionView::Private::itemCurrentChanged( const QModelIndex &index ) -{ - if ( !index.isValid() ) - return; - - const Collection col = index.model()->data( index, CollectionModel::CollectionRole ).value(); - if ( !col.isValid() ) - return; - - emit mParent->currentChanged( col ); -} - -CollectionView::CollectionView(QWidget * parent) : - QTreeView( parent ), - d( new Private( this ) ) -{ - d->init(); -} - -CollectionView::CollectionView( KXmlGuiWindow *xmlGuiWindow, QWidget * parent ) : - QTreeView( parent ), - d( new Private( this ) ) -{ - d->xmlGuiWindow = xmlGuiWindow; - d->init(); -} - -CollectionView::~CollectionView() -{ - delete d; -} - -void CollectionView::setModel( QAbstractItemModel * model ) -{ - QTreeView::setModel( model ); - header()->setStretchLastSection( true ); - - connect( selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), - this, SLOT( itemCurrentChanged( const QModelIndex& ) ) ); -} - -void CollectionView::dragMoveEvent(QDragMoveEvent * event) -{ - QModelIndex index = indexAt( event->pos() ); - if ( d->dragOverIndex != index ) { - d->dragExpandTimer.stop(); - if ( index.isValid() && !isExpanded( index ) && itemsExpandable() ) { - d->dragExpandTimer.start( QApplication::startDragTime() ); - d->dragOverIndex = index; - } - } - - // Check if the collection under the cursor accepts this data type - QStringList supportedContentTypes = model()->data( index, CollectionModel::CollectionRole ).value().contentMimeTypes(); - const QMimeData *data = event->mimeData(); - KUrl::List urls = KUrl::List::fromMimeData( data ); - foreach( const KUrl &url, urls ) { - - const Collection collection = Collection::fromUrl( url ); - if ( collection.isValid() ) - { - if ( !supportedContentTypes.contains( QString::fromLatin1( "inode/directory" ) ) ) - break; - - // Check if we don't try to drop on one of the children - if ( d->hasParent( index, collection.id() ) ) - break; - } - else - { - QString type = url.queryItems()[ QString::fromLatin1("type") ]; - if ( !supportedContentTypes.contains( type ) ) - break; - } - - QTreeView::dragMoveEvent( event ); - return; - } - - event->setDropAction( Qt::IgnoreAction ); - return; -} - -void CollectionView::dragLeaveEvent(QDragLeaveEvent * event) -{ - d->dragExpandTimer.stop(); - d->dragOverIndex = QModelIndex(); - QTreeView::dragLeaveEvent( event ); -} - - -void CollectionView::dropEvent(QDropEvent * event) -{ - d->dragExpandTimer.stop(); - d->dragOverIndex = QModelIndex(); - - // open a context menu offering different drop actions (move, copy and cancel) - // TODO If possible, hide non available actions ... - QMenu popup( this ); - QAction* moveDropAction = popup.addAction( KIcon( QString::fromLatin1("edit-rename") ), i18n("&Move here") ); - QAction* copyDropAction = popup.addAction( KIcon( QString::fromLatin1("edit-copy") ), i18n("&Copy here") ); - popup.addSeparator(); - popup.addAction( KIcon( QString::fromLatin1("process-stop") ), i18n("Cancel")); - - QAction *activatedAction = popup.exec( QCursor::pos() ); - if (activatedAction == moveDropAction) { - event->setDropAction( Qt::MoveAction ); - } - else if (activatedAction == copyDropAction) { - event->setDropAction( Qt::CopyAction ); - } - else return; - - QTreeView::dropEvent( event ); -} - -void CollectionView::contextMenuEvent(QContextMenuEvent * event) -{ - if ( !d->xmlGuiWindow ) - return; - QMenu *popup = static_cast( d->xmlGuiWindow->guiFactory()->container( - QLatin1String("akonadi_collectionview_contextmenu"), d->xmlGuiWindow ) ); - if ( popup ) - popup->exec( event->globalPos() ); -} - -void CollectionView::setXmlGuiWindow(KXmlGuiWindow * xmlGuiWindow) -{ - d->xmlGuiWindow = xmlGuiWindow; -} - -#include "collectionview.moc" diff --git a/akonadi/collectionview.h b/akonadi/collectionview.h deleted file mode 100644 index 6cc02ebc1..000000000 --- a/akonadi/collectionview.h +++ /dev/null @@ -1,136 +0,0 @@ -/* - Copyright (c) 2006 - 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_COLLECTION_VIEW -#define AKONADI_COLLECTION_VIEW - -#include "akonadi_export.h" -#include - -class KXmlGuiWindow; -class QDragMoveEvent; - -namespace Akonadi { - -class Collection; - -/** - * @short A view to show a collection tree provided by a CollectionModel. - * - * When a KXmlGuiWindow is passed to the constructor, the XMLGUI - * defined context menu @c akonadi_collectionview_contextmenu is - * used if available. - * - * Example: - * - * @code - * - * class MyWindow : public KXmlGuiWindow - * { - * public: - * MyWindow() - * : KXmlGuiWindow() - * { - * Akonadi::CollectionView *view = new Akonadi::CollectionView( this, this ); - * setCentralWidget( view ); - * - * Akonadi::CollectionModel *model = new Akonadi::CollectionModel( this ); - * view->setModel( model ); - * } - * } - * - * @endcode - * - * @author Volker Krause - */ -class AKONADI_EXPORT CollectionView : public QTreeView -{ - Q_OBJECT - - public: - /** - * Creates a new collection view. - * - * @param parent The parent widget. - */ - explicit CollectionView( QWidget *parent = 0 ); - - /** - * Creates a new collection view. - * - * @param xmlGuiWindow The KXmlGuiWindow the view is used in. - * This is needed for the XMLGUI based context menu. - * Passing 0 is ok and will disable the builtin context menu. - * @param parent The parent widget. - */ - explicit CollectionView( KXmlGuiWindow *xmlGuiWindow, QWidget *parent = 0 ); - - /** - * Destroys the collection view. - */ - virtual ~CollectionView(); - - /** - * Sets the KXmlGuiWindow which the view is used in. - * This is needed if you want to use the built-in context menu. - * - * @param xmlGuiWindow The KXmlGuiWindow the view is used in. - */ - void setXmlGuiWindow( KXmlGuiWindow *xmlGuiWindow ); - - virtual void setModel ( QAbstractItemModel * model ); - - Q_SIGNALS: - /** - * This signal is emitted whenever the user has clicked - * a collection in the view. - * - * @param collection The clicked collection. - */ - void clicked( const Akonadi::Collection &collection ); - - /** - * This signal is emitted whenever the current collection - * in the view has changed. - * - * @param collection The new current collection. - */ - void currentChanged( const Akonadi::Collection &collection ); - - protected: - using QTreeView::currentChanged; - virtual void dragMoveEvent( QDragMoveEvent *event ); - virtual void dragLeaveEvent( QDragLeaveEvent *event ); - virtual void dropEvent( QDropEvent *event ); - virtual void contextMenuEvent( QContextMenuEvent *event ); - - private: - //@cond PRIVATE - class Private; - Private * const d; - - Q_PRIVATE_SLOT( d, void dragExpand() ) - Q_PRIVATE_SLOT( d, void itemClicked( const QModelIndex& ) ) - Q_PRIVATE_SLOT( d, void itemCurrentChanged( const QModelIndex& ) ) - //@endcond -}; - -} - -#endif diff --git a/akonadi/control.cpp b/akonadi/control.cpp deleted file mode 100644 index a06cb2351..000000000 --- a/akonadi/control.cpp +++ /dev/null @@ -1,125 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "control.h" - -#include -#include - -#include -#include -#include -#include -#include - -#define AKONADI_CONTROL_SERVICE QLatin1String("org.freedesktop.Akonadi.Control") -#define AKONADI_SERVER_SERVICE QLatin1String("org.freedesktop.Akonadi") - -using namespace Akonadi; - -/** - * @internal - */ -class Control::Private -{ - public: - Private( Control *parent ) - : mParent( parent ), mEventLoop( 0 ), mSuccess( false ) - { - } - - bool startInternal(); - void serviceOwnerChanged( const QString&, const QString&, const QString& ); - - Control *mParent; - QEventLoop *mEventLoop; - bool mSuccess; -}; - -class StaticControl : public Control -{ - public: - StaticControl() : Control() {} -}; - -K_GLOBAL_STATIC( StaticControl, s_instance ) - - -bool Control::Private::startInternal() -{ - if ( QDBusConnection::sessionBus().interface()->isServiceRegistered( AKONADI_CONTROL_SERVICE ) || mEventLoop ) - return true; - - QDBusReply reply = QDBusConnection::sessionBus().interface()->startService( AKONADI_CONTROL_SERVICE ); - if ( !reply.isValid() ) { - kWarning( 5250 ) << "Unable to start Akonadi control process: " - << reply.error().message(); - - // start via D-Bus .service file didn't work, let's try starting the process manually - if ( reply.error().type() == QDBusError::ServiceUnknown ) { - const bool ok = QProcess::startDetached( QLatin1String("akonadi_control") ); - if ( !ok ) { - kWarning( 5250 ) << "Error: unable to execute binary akonadi_control"; - return false; - } - } else { - return false; - } - } - - mEventLoop = new QEventLoop( mParent ); - // safety timeout - QTimer::singleShot( 10000, mEventLoop, SLOT(quit()) ); - mEventLoop->exec(); - mEventLoop->deleteLater(); - mEventLoop = 0; - - if ( !mSuccess ) - kWarning( 5250 ) << "Could not start Akonadi!"; - return mSuccess; -} - -void Control::Private::serviceOwnerChanged( const QString & name, const QString & oldOwner, const QString & newOwner ) -{ - Q_UNUSED( oldOwner ); - if ( name == AKONADI_SERVER_SERVICE && !newOwner.isEmpty() && mEventLoop && mEventLoop->isRunning() ) { - mEventLoop->quit(); - mSuccess = true; - } -} - - -Control::Control() - : d( new Private( this ) ) -{ - connect( QDBusConnection::sessionBus().interface(), SIGNAL( serviceOwnerChanged( QString, QString, QString ) ), - SLOT( serviceOwnerChanged( QString, QString, QString ) ) ); -} - -Control::~Control() -{ - delete d; -} - -bool Control::start() -{ - return s_instance->d->startInternal(); -} - -#include "control.moc" diff --git a/akonadi/control.h b/akonadi/control.h deleted file mode 100644 index 3d0e1aafb..000000000 --- a/akonadi/control.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_CONTROL_H -#define AKONADI_CONTROL_H - -#include "akonadi_export.h" -#include - - -namespace Akonadi { - -/** - * @short Provides methods to control the Akonadi server process. - * - * This class provides a method to start the Akonadi server - * process synchronously. - * - * Normally the Akonadi server is started by the KDE session - * manager, however for unit tests or special needs one can - * use this class to start it explicitly. - * - * Example: - * - * @code - * - * if ( !Akonadi::Control::start() ) { - * qDebug() << "Unable to start server, exit application"; - * return 1; - * } else { - * ... - * } - * - * @endcode - * - * @author Volker Krause - */ -class AKONADI_EXPORT Control : public QObject -{ - Q_OBJECT - - public: - /** - * Destroys the control object. - */ - ~Control(); - - /** - * Starts the Akonadi server synchronously if it is not already running. - */ - static bool start(); - - protected: - /** - * Creates the control object. - */ - Control(); - - private: - //@cond PRIVATE - class Private; - Private* const d; - - Q_PRIVATE_SLOT( d, void serviceOwnerChanged( const QString&, const QString&, const QString& ) ) - //@endcond -}; - -} - -#endif diff --git a/akonadi/entity.cpp b/akonadi/entity.cpp deleted file mode 100644 index cc8f3353e..000000000 --- a/akonadi/entity.cpp +++ /dev/null @@ -1,129 +0,0 @@ -/* - Copyright (c) 2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "entity.h" -#include "entity_p.h" - -using namespace Akonadi; - -Entity::Entity( const Entity &other ) - : d_ptr( other.d_ptr ) -{ -} - -Entity::Entity( EntityPrivate *dd ) - : d_ptr( dd ) -{ -} - -Entity::~Entity() -{ -} - -void Entity::setId( Id id ) -{ - d_ptr->mId = id; -} - -Entity::Id Entity::id() const -{ - return d_ptr->mId; -} - -void Entity::setRemoteId( const QString& id ) -{ - d_ptr->mRemoteId = id; -} - -QString Entity::remoteId() const -{ - return d_ptr->mRemoteId; -} - -bool Entity::isValid() const -{ - return ( d_ptr->mId >= 0 ); -} - -bool Entity::operator==( const Entity &other ) const -{ - return ( d_ptr->mId == other.d_ptr->mId ); -} - -bool Akonadi::Entity::operator!=(const Entity & other) const -{ - return d_ptr->mId != other.d_ptr->mId; -} - -Entity& Entity ::operator=( const Entity &other ) -{ - if ( this != &other ) - d_ptr = other.d_ptr; - - return *this; -} - -void Entity::addAttribute(Attribute * attr) -{ - if ( d_ptr->mAttributes.contains( attr->type() ) ) - delete d_ptr->mAttributes.take( attr->type() ); - d_ptr->mAttributes.insert( attr->type(), attr ); - d_ptr->mDeletedAttributes.remove( attr->type() ); -} - -void Entity::removeAttribute( const QByteArray &type ) -{ - if ( d_ptr->mAttributes.contains( type ) ) { - d_ptr->mDeletedAttributes.insert( type ); - delete d_ptr->mAttributes.take( type ); - } -} - -bool Entity::hasAttribute(const QByteArray & type) const -{ - return d_ptr->mAttributes.contains( type ); -} - -Attribute::List Entity::attributes() const -{ - return d_ptr->mAttributes.values(); -} - -void Akonadi::Entity::clearAttributes() -{ - foreach ( Attribute *attr, d_ptr->mAttributes ) { - d_ptr->mDeletedAttributes.insert( attr->type() ); - delete attr; - } - d_ptr->mAttributes.clear(); -} - -Attribute * Entity::attribute(const QByteArray & type) const -{ - if ( d_ptr->mAttributes.contains( type ) ) - return d_ptr->mAttributes.value( type ); - return 0; -} - -uint qHash( const Akonadi::Entity &entity ) -{ - return qHash( entity.id() ); -} - -AKONADI_DEFINE_PRIVATE( Entity ) diff --git a/akonadi/entity.h b/akonadi/entity.h deleted file mode 100644 index 6a9514623..000000000 --- a/akonadi/entity.h +++ /dev/null @@ -1,221 +0,0 @@ -/* - Copyright (c) 2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_ENTITY_H -#define AKONADI_ENTITY_H - -#include "akonadi_export.h" - -namespace Akonadi { -class Entity; -} - -AKONADI_EXPORT uint qHash( const Akonadi::Entity& ); - -#include - -#include -#include - -#define AKONADI_DECLARE_PRIVATE( Class ) \ - Class##Private* d_func(); \ - const Class##Private* d_func() const; \ - friend class Class##Private; - -namespace Akonadi { - -class EntityPrivate; - -/** - * @short The base class for Item and Collection. - * - * Entity is the common base class for Item and Collection that provides - * unique IDs and attributes handling. - * - * This class is not meant to be used directly, use Item or Collection instead. - * - * @author Tobias Koenig - */ -class AKONADI_EXPORT Entity -{ - public: - /** - * Describes the unique id type. - */ - typedef qint64 Id; - - /** - * Destroys the entity. - */ - ~Entity(); - - /** - * Sets the unique @p identifier of the entity. - */ - void setId( Id identifier ); - - /** - * Returns the unique identifier of the entity. - */ - Id id() const; - - /** - * Sets the remote @p id of the entity. - */ - void setRemoteId( const QString& id ); - - /** - * Returns the remote id of the entity. - */ - QString remoteId() const; - - /** - * Returns whether the entity is valid. - */ - bool isValid() const; - - /** - * Returns whether the entity's id equals the - * id of the @p other entity. - */ - bool operator==( const Entity &other ) const; - - /** - * Returns whether the entity's id does not equal the id - * of the @p other entity. - */ - bool operator!=( const Entity &other ) const; - - /** - * Assigns the @p other to this entity and returns a reference to this entity. - */ - Entity& operator=( const Entity &other ); - - /** - * Adds an attribute to the entity. - * - * If an attribute of the same type name already exists, it is deleted and - * replaced with the new one. - * - * @param attribute The new attribute. - * - * @note The entity takes the ownership of the attribute. - */ - void addAttribute( Attribute *attribute ); - - /** - * Removes and deletes the attribute of the given type @p name. - */ - void removeAttribute( const QByteArray &name ); - - /** - * Returns @c true if the entity has an attribute of the given type @p name, - * false otherwise. - */ - bool hasAttribute( const QByteArray &name ) const; - - /** - * Returns a list of all attributes of the entity. - */ - Attribute::List attributes() const; - - /** - * Removes and deletes all attributes of the entity. - */ - void clearAttributes(); - - /** - * Returns the attribute of the given type @p name if available, 0 otherwise. - */ - Attribute* attribute( const QByteArray &name ) const; - - /** - * Describes the options that can be passed to access attributes. - */ - enum CreateOption - { - AddIfMissing ///< Creates the attribute if it is missing - }; - - /** - * Returns the attribute of the requested type. - * If the entity has no attribute of that type yet, a new one - * is created and added to the entity. - * - * @param option The create options. - */ - template inline T* attribute( CreateOption option ) - { - Q_UNUSED( option ); - - const T dummy; - if ( hasAttribute( dummy.type() ) ) - return static_cast( attribute( dummy.type() ) ); - - T* attr = new T(); - addAttribute( attr ); - return attr; - } - - /** - * Returns the attribute of the requested type or 0 if it is not available. - */ - template inline T* attribute() const - { - const T dummy; - if ( hasAttribute( dummy.type() ) ) - return static_cast( attribute( dummy.type() ) ); - return 0; - } - - /** - * Removes and deletes the attribute of the requested type. - */ - template inline void removeAttribute() - { - const T dummy; - removeAttribute( dummy.type() ); - } - - /** - * Returns whether the entity has an attribute of the requested type. - */ - template inline bool hasAttribute() const - { - const T dummy; - return hasAttribute( dummy.type() ); - } - - protected: - /** - * Creates an entity from an @p other entity. - */ - Entity( const Entity &other ); - - //@cond PRIVATE - Entity( EntityPrivate *dd ); - QSharedDataPointer d_ptr; - //@endcond - - AKONADI_DECLARE_PRIVATE( Entity ) -}; - -} - -#endif diff --git a/akonadi/entity_p.h b/akonadi/entity_p.h deleted file mode 100644 index f5b925b34..000000000 --- a/akonadi/entity_p.h +++ /dev/null @@ -1,95 +0,0 @@ -/* - Copyright (c) 2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef ENTITY_P_H -#define ENTITY_P_H - -#include "entity.h" - -#include -#include -#include - -#define AKONADI_DEFINE_PRIVATE( Class ) \ -Class##Private* Class ::d_func() { return reinterpret_cast( d_ptr.data() ); } \ -const Class##Private* Class ::d_func() const { return reinterpret_cast( d_ptr.data() ); } - -namespace Akonadi { - -/** - * @internal - */ -class EntityPrivate : public QSharedData -{ - public: - EntityPrivate( Entity::Id id = -1 ) - : mId( id ) - { - } - - virtual ~EntityPrivate() - { - qDeleteAll( mAttributes ); - } - - EntityPrivate( const EntityPrivate &other ) - : QSharedData( other ) - { - mId = other.mId; - mRemoteId = other.mRemoteId; - foreach ( Attribute* attr, other.mAttributes ) - mAttributes.insert( attr->type(), attr->clone() ); - mDeletedAttributes = other.mDeletedAttributes; - } - - virtual void resetChangeLog() - { - mDeletedAttributes.clear(); - } - - virtual EntityPrivate *clone() const = 0; - - Entity::Id mId; - QString mRemoteId; - QHash mAttributes; - QSet mDeletedAttributes; -}; - -} - -/** - * @internal - * - * This template specialization is used to change the detach - * behaviour of QSharedDataPointer to match our needs. - */ -template <> -Q_INLINE_TEMPLATE void QSharedDataPointer::detach() -{ - if (d && d->ref != 1) - { - Akonadi::EntityPrivate *x = d->clone(); - x->ref.ref(); - if (!d->ref.deref()) - delete d; - d = x; - } -} - -#endif diff --git a/akonadi/expungejob.cpp b/akonadi/expungejob.cpp deleted file mode 100644 index 2a30faaa7..000000000 --- a/akonadi/expungejob.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "expungejob.h" - -#include "job_p.h" - -using namespace Akonadi; - -class Akonadi::ExpungeJobPrivate : public JobPrivate -{ - public: - ExpungeJobPrivate( ExpungeJob * parent ) - : JobPrivate( parent ) - { - } -}; - -ExpungeJob::ExpungeJob(QObject * parent) - : Job( new ExpungeJobPrivate( this ), parent ) -{ -} - -ExpungeJob::~ExpungeJob() -{ -} - -void ExpungeJob::doStart() -{ - d_ptr->writeData( d_ptr->newTag() + " EXPUNGE\n" ); -} - -#include "expungejob.moc" diff --git a/akonadi/expungejob.h b/akonadi/expungejob.h deleted file mode 100644 index 566ce703f..000000000 --- a/akonadi/expungejob.h +++ /dev/null @@ -1,59 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_EXPUNGEJOB_H -#define AKONADI_EXPUNGEJOB_H - -#include "job.h" - -namespace Akonadi { - -class ExpungeJobPrivate; - -/** - * @internal - * - * Permanently removes all items marked for deletion. - */ -class ExpungeJob : public Job -{ - Q_OBJECT - - public: - /** - Creates a new ExpungeJob. - @param parent The parent object. - */ - explicit ExpungeJob( QObject *parent = 0 ); - - /** - Destroys this job. - */ - virtual ~ExpungeJob(); - - protected: - virtual void doStart(); - - private: - Q_DECLARE_PRIVATE( ExpungeJob ) -}; - -} - -#endif diff --git a/akonadi/flatcollectionproxymodel.cpp b/akonadi/flatcollectionproxymodel.cpp deleted file mode 100644 index ce83ca812..000000000 --- a/akonadi/flatcollectionproxymodel.cpp +++ /dev/null @@ -1,164 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "flatcollectionproxymodel.h" - -#include - -using namespace Akonadi; - -/** - * @internal - */ -class FlatCollectionProxyModel::Private -{ - public: - Private( FlatCollectionProxyModel* parent ) : q( parent ) {} - - // ### SLOW! - static int totalCount( QAbstractItemModel *model, const QModelIndex &index ) - { - Q_ASSERT( model ); - const int rows = model->rowCount( index ); - int count = rows; - for ( int i = 0; i < rows; ++i ) { - QModelIndex current = model->index( i, 0, index ); - if ( current.isValid() ) - count += totalCount( model, current ); - } - return count; - } - - // ### EVEN SLOWER, and even called multiple times in a row! - static QModelIndex findSourceIndex( QAbstractItemModel *model, int _row, int col, const QModelIndex &parent = QModelIndex() ) - { - int row = _row; - Q_ASSERT( model ); - for ( int i = 0; i <= row; ++i ) { - QModelIndex current = model->index( i, col, parent ); - if ( i == row ) - return current; - const int childCount = totalCount( model, current ); - if ( childCount >= ( row - i ) ) - return findSourceIndex( model, row - i - 1, col, current ); - else - row -= childCount; - } - Q_ASSERT( false ); - return QModelIndex(); - } - - void sourceDataChanged( const QModelIndex &sourceTopLeft, const QModelIndex &sourceBottomRight ) - { - if ( sourceTopLeft != sourceBottomRight ) { - emit q->dataChanged( q->mapFromSource( sourceTopLeft ), q->mapFromSource( sourceBottomRight ) ); - } else { - const QModelIndex proxyIndex = q->mapFromSource( sourceTopLeft ); - emit q->dataChanged( proxyIndex, proxyIndex ); - } - } - - FlatCollectionProxyModel *q; -}; - -FlatCollectionProxyModel::FlatCollectionProxyModel(QObject * parent) : - QAbstractProxyModel( parent ), - d( new Private( this ) ) -{ -} - -FlatCollectionProxyModel::~FlatCollectionProxyModel() -{ - delete d; -} - -void FlatCollectionProxyModel::setSourceModel(QAbstractItemModel * sourceModel) -{ - QAbstractProxyModel::setSourceModel( sourceModel ); - connect( sourceModel, SIGNAL(modelReset()), SIGNAL(modelReset()) ); - connect( sourceModel, SIGNAL(layoutChanged()), SIGNAL(layoutChanged()) ); - connect( sourceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)), - SLOT(sourceDataChanged(QModelIndex,QModelIndex)) ); -} - -int FlatCollectionProxyModel::rowCount(const QModelIndex & parent) const -{ - if ( parent.isValid() ) - return 0; - return d->totalCount( sourceModel(), mapToSource( parent ) ); -} - -int FlatCollectionProxyModel::columnCount(const QModelIndex & parent) const -{ - return sourceModel()->columnCount( mapToSource( parent ) ); -} - -QModelIndex FlatCollectionProxyModel::index(int row, int column, const QModelIndex & parent) const -{ - Q_UNUSED( parent ); - return createIndex( row, column ); -} - -QModelIndex FlatCollectionProxyModel::parent(const QModelIndex & index) const -{ - Q_UNUSED( index ); - return QModelIndex(); -} - -QModelIndex FlatCollectionProxyModel::mapToSource(const QModelIndex & proxyIndex) const -{ - if ( !proxyIndex.isValid() ) - return QModelIndex(); - return d->findSourceIndex( sourceModel(), proxyIndex.row(), proxyIndex.column() ); -} - -QModelIndex FlatCollectionProxyModel::mapFromSource(const QModelIndex & sourceIndex) const -{ - if ( !sourceIndex.isValid() ) - return QModelIndex(); - int row = 0; - QModelIndex current = sourceIndex; - while ( current.parent() != QModelIndex() ) { - row += current.row() + 1; - for ( int i = current.row() - 1; i >= 0; --i ) - row += d->totalCount( sourceModel(), sourceModel()->index( i, 0, current.parent() ) ); - current = current.parent(); - } - row += current.row(); - for ( int i = current.row() - 1; i >= 0; --i ) - row += d->totalCount( sourceModel(), sourceModel()->index( i, 0 ) ); - return createIndex( row, sourceIndex.column() ); -} - -QVariant FlatCollectionProxyModel::data(const QModelIndex & index, int role) const -{ - if ( role == Qt::DisplayRole ) { - QModelIndex sourceIndex = mapToSource( index ); - QString name = sourceIndex.data( role ).toString(); - sourceIndex = sourceIndex.parent(); - while ( sourceIndex.isValid() ) { - name.prepend( sourceIndex.data( role ).toString() + QLatin1String( "/" ) ); - sourceIndex = sourceIndex.parent(); - } - return name; - } - return QAbstractProxyModel::data( index, role ); -} - -#include "flatcollectionproxymodel.moc" diff --git a/akonadi/flatcollectionproxymodel.h b/akonadi/flatcollectionproxymodel.h deleted file mode 100644 index 4a1d3b935..000000000 --- a/akonadi/flatcollectionproxymodel.h +++ /dev/null @@ -1,69 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_FLATCOLLECTIONPROXYMODEL_H -#define AKONADI_FLATCOLLECTIONPROXYMODEL_H - -#include - -namespace Akonadi { - -/** - * @internal - * - * Converts the hierarchical collection model into a flat one. - * - * @todo Make this fast. And maybe even generic. - */ -class FlatCollectionProxyModel : public QAbstractProxyModel -{ - Q_OBJECT - public: - /** - Create a new flat collection proxy model. - @param parent The parent object. - */ - FlatCollectionProxyModel( QObject *parent = 0 ); - - /** - Destructor. - */ - ~FlatCollectionProxyModel(); - - void setSourceModel ( QAbstractItemModel * sourceModel ); - - QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) const; - int rowCount( const QModelIndex & parent = QModelIndex() ) const; - int columnCount(const QModelIndex &parent = QModelIndex()) const; - QModelIndex index( int row, int column, const QModelIndex & parent = QModelIndex() ) const; - QModelIndex parent( const QModelIndex & index ) const; - - QModelIndex mapFromSource ( const QModelIndex & sourceIndex ) const; - QModelIndex mapToSource ( const QModelIndex & proxyIndex ) const; - - private: - class Private; - Private* const d; - - Q_PRIVATE_SLOT( d, void sourceDataChanged( const QModelIndex &, const QModelIndex & ) ) -}; - -} - -#endif diff --git a/akonadi/item.cpp b/akonadi/item.cpp deleted file mode 100644 index 8f1e4cc51..000000000 --- a/akonadi/item.cpp +++ /dev/null @@ -1,180 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "item.h" -#include "item_p.h" -#include "itemserializer.h" -#include "protocol_p.h" - -#include - -#include - -using namespace Akonadi; - -// Change to something != RFC822 as soon as the server supports it -const char* Item::FullPayload = "RFC822"; - -Item::Item() - : Entity( new ItemPrivate ) -{ -} - -Item::Item( Id id ) - : Entity( new ItemPrivate( id ) ) -{ -} - -Item::Item( const QString & mimeType ) - : Entity( new ItemPrivate ) -{ - d_func()->mMimeType = mimeType; -} - -Item::Item( const Item &other ) - : Entity( other ) -{ -} - -Item::~Item() -{ -} - -Item::Flags Item::flags() const -{ - return d_func()->mFlags; -} - -void Item::setFlag( const QByteArray & name ) -{ - Q_D( Item ); - d->mFlags.insert( name ); - if ( !d->mFlagsOverwritten ) - d->mAddedFlags.insert( name ); -} - -void Item::clearFlag( const QByteArray & name ) -{ - Q_D( Item ); - d->mFlags.remove( name ); - if ( !d->mFlagsOverwritten ) - d->mDeletedFlags.insert( name ); -} - -void Item::setFlags( const Flags &flags ) -{ - Q_D( Item ); - d->mFlags = flags; - d->mFlagsOverwritten = true; -} - -void Item::clearFlags() -{ - Q_D( Item ); - d->mFlags.clear(); - d->mFlagsOverwritten = true; -} - -bool Item::hasFlag( const QByteArray & name ) const -{ - return d_func()->mFlags.contains( name ); -} - -QSet Item::loadedPayloadParts() const -{ - return ItemSerializer::parts( *this ); -} - -QByteArray Item::payloadData() const -{ - int version = 0; - QByteArray data; - ItemSerializer::serialize( *this, FullPayload, data, version ); - return data; -} - -void Item::setPayloadFromData( const QByteArray &data ) -{ - ItemSerializer::deserialize( *this, FullPayload, data, 0 ); -} - -int Item::revision() const -{ - return d_func()->mRevision; -} - -void Item::setRevision( int rev ) -{ - d_func()->mRevision = rev; -} - -QString Item::mimeType() const -{ - return d_func()->mMimeType; -} - -void Item::setMimeType( const QString & mimeType ) -{ - d_func()->mMimeType = mimeType; -} - -bool Item::hasPayload() const -{ - return d_func()->mPayload != 0; -} - -KUrl Item::url( UrlType type ) const -{ - KUrl url; - url.setProtocol( QString::fromLatin1("akonadi") ); - url.addQueryItem( QLatin1String( "item" ), QString::number( id() ) ); - - if ( type == UrlWithMimeType ) - url.addQueryItem( QLatin1String( "type" ), mimeType() ); - - return url; -} - -Item Item::fromUrl( const KUrl &url ) -{ - if ( url.protocol() != QLatin1String( "akonadi" ) ) - return Item(); - - const QString itemStr = url.queryItem( QLatin1String( "item" ) ); - bool ok = false; - Item::Id itemId = itemStr.toLongLong( &ok ); - if ( !ok ) - return Item(); - - return Item( itemId ); -} - -PayloadBase* Item::payloadBase() const -{ - return d_func()->mPayload; -} - -void Item::setPayloadBase( PayloadBase* p ) -{ - Q_D( Item ); - delete d->mPayload; - d->mPayload = p; -} - -AKONADI_DEFINE_PRIVATE( Item ) diff --git a/akonadi/item.h b/akonadi/item.h deleted file mode 100644 index 418a620b1..000000000 --- a/akonadi/item.h +++ /dev/null @@ -1,281 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - 2007 Till Adam - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_ITEM_H -#define AKONADI_ITEM_H - -#include "akonadi_export.h" - -#include - -#include -#include -#include - -#include - -class KUrl; - -namespace Akonadi { - -class ItemPrivate; - -#include "itempayloadinternals_p.h" - -/** - * @short Represents a PIM item stored in Akonadi storage. - * - * A PIM item consists of one or more parts, allowing a fine-grained access on its - * content where needed (eg. mail envelope, mail body and attachments). - * - * There is also a namespace (prefix) for special parts which are local to Akonadi. - * These parts, prefixed by "akonadi-" will never be fetched in the resource. - * They are useful for local extensions like agents which might want to add meta data - * to items in order to handle them but the meta data should not be stored back to the - * resource. - * - * This class contains beside some type-agnostic information (flags, revision) - * a single payload object representing its actual data. Which objects these actually - * are depends on the mimetype of the item and the corresponding serializer plugin. - * - * This class is implicitly shared. - * - * @author Volker Krause , Till Adam - */ -class AKONADI_EXPORT Item : public Entity -{ - public: - /** - * Describes a list of items. - */ - typedef QList List; - - /** - * Describes a flag name. - */ - typedef QByteArray Flag; - - /** - * Describes a set of flag names. - */ - typedef QSet Flags; - - /** - * Describes the part name that is used to fetch the - * full payload of an item. - */ - static const char* FullPayload; - - /** - * Creates a new item. - */ - Item(); - - /** - * Creates a new item with the given unique @p id. - */ - explicit Item( Id id ); - - /** - * Creates a new item with the given mime type. - * - * @param mimeType The mime type of the item. - */ - explicit Item( const QString &mimeType ); - - /** - * Creates a new item from an @p other item. - */ - Item( const Item &other ); - - /** - * Destroys the item. - */ - ~Item(); - - /** - * Creates an item from the given @p url. - */ - static Item fromUrl( const KUrl &url ); - - /** - * Returns all flags of this item. - */ - Flags flags() const; - - /** - * Returns whether the flag with the given @p name is - * set in the item. - */ - bool hasFlag( const QByteArray &name ) const; - - /** - * Sets the flag with the given @p name in the item. - */ - void setFlag( const QByteArray &name ); - - /** - * Removes the flag with the given @p name from the item. - */ - void clearFlag( const QByteArray &name ); - - /** - * Overwrites all flags of the item by the given @p flags. - */ - void setFlags( const Flags &flags ); - - /** - * Removes all flags from the item. - */ - void clearFlags(); - - /** - * Sets the payload based on the canonical representation normally - * used for data of this mime type. - * - * @param data The encoded data. - * @see fullPayloadData - */ - void setPayloadFromData( const QByteArray &data ); - - /** - * Returns the full payload in its canonical representation, e.g. the - * binary or textual format usually used for data with this mime type. - * This is useful when communicating with non-Akonadi application by - * e.g. drag&drop, copy&paste or stored files. - */ - QByteArray payloadData() const; - - /** - * Returns the list of loaded payload parts. This is not necessarily - * identical to all parts in the cache or to all available parts on the backend. - */ - QSet loadedPayloadParts() const; - - /** - * Sets the @p revision number of the item. - * - * @note Do not modify this value from within an application, - * it is updated automatically by the revision checking functions. - */ - void setRevision( int revision ); - - /** - * Returns the revision number of the item. - */ - int revision() const; - - /** - * Sets the mime type of the item to @p mimeType. - */ - void setMimeType( const QString &mimeType ); - - /** - * Returns the mime type of the item. - */ - QString mimeType() const; - - /** - * Sets the payload object of this PIM item. - * - * The payload MUST NOT be a pointer, use a boost::shared_ptr instead. - * The payload should be an implicitly shared class. - */ - template - void setPayload( T p ) - { - setPayloadBase( new Payload( p ) ); - } - - /** - * Returns the payload object of this PIM item. - * - * @note This method will abort the application if you try to - * retrieve the wrong payload type, so better always check - * the mime type first. - */ - template - T payload() const - { - if ( !payloadBase() ) Q_ASSERT_X(false, "Akonadi::Item::payload()", "No valid payload set."); - - Payload *p = dynamic_cast*>( payloadBase() ); - // try harder to cast, workaround for some gcc issue with template instances in multiple DSO's - if ( !p && strcmp( payloadBase()->typeName(), typeid(p).name() ) == 0 ) { - p = reinterpret_cast*>( payloadBase() ); - } - if ( !p ) - qFatal( "Akonadi::Item::payload(): Wrong payload type (is '%s', requested '%s')", - payloadBase()->typeName(), typeid(p).name() ); - return p->payload; - } - - /** - * Returns whether the item has a payload object. - */ - bool hasPayload() const; - - /** - * Returns whether the item has a payload of type @c T. - */ - template - bool hasPayload() const - { - if ( !hasPayload() ) - return false; - Payload *p = dynamic_cast*>( payloadBase() ); - // try harder to cast, workaround for some gcc issue with template instances in multiple DSO's - if ( !p && strcmp( payloadBase()->typeName(), typeid(p).name() ) == 0 ) { - p = reinterpret_cast*>( payloadBase() ); - } - return p; - } - - /** - * Describes the type of url which is returned in url(). - */ - enum UrlType - { - UrlShort = 0, ///< A short url which contains the identifier only (default) - UrlWithMimeType = 1 ///< A url with identifier and mimetype - }; - - /** - * Returns the url of the item. - */ - KUrl url( UrlType type = UrlShort ) const; - - private: - //@cond PRIVATE - friend class ItemModifyJob; - friend class ItemFetchJob; - PayloadBase* payloadBase() const; - void setPayloadBase( PayloadBase* ); - //@endcond - - AKONADI_DECLARE_PRIVATE( Item ) -}; - -} - -Q_DECLARE_METATYPE(Akonadi::Item) -Q_DECLARE_METATYPE(Akonadi::Item::List) - -#endif diff --git a/akonadi/item_p.h b/akonadi/item_p.h deleted file mode 100644 index 04eb2e2e3..000000000 --- a/akonadi/item_p.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - Copyright (c) 2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_ITEM_P_H -#define AKONADI_ITEM_P_H - -#include - -#include "entity_p.h" -#include "itempayloadinternals_p.h" - -namespace Akonadi { - -/** - * @internal - */ -class ItemPrivate : public EntityPrivate -{ - public: - ItemPrivate( Item::Id id = -1 ) - : EntityPrivate( id ), - mPayload( 0 ), - mRevision( -1 ), - mFlagsOverwritten( false ) - { - } - - ItemPrivate( const ItemPrivate &other ) - : EntityPrivate( other ) - { - mFlags = other.mFlags; - mRevision = other.mRevision; - mMimeType = other.mMimeType; - if ( other.mPayload ) - mPayload = other.mPayload->clone(); - else - mPayload = 0; - } - - ~ItemPrivate() - { - delete mPayload; - } - - void resetChangeLog() - { - mFlagsOverwritten = false; - mAddedFlags.clear(); - mDeletedFlags.clear(); - } - - EntityPrivate *clone() const - { - return new ItemPrivate( *this ); - } - - PayloadBase* mPayload; - Item::Flags mFlags; - int mRevision; - QString mMimeType; - Item::Flags mAddedFlags; - Item::Flags mDeletedFlags; - bool mFlagsOverwritten; -}; - -} - -#endif - diff --git a/akonadi/itemcopyjob.cpp b/akonadi/itemcopyjob.cpp deleted file mode 100644 index 62f75aea6..000000000 --- a/akonadi/itemcopyjob.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "itemcopyjob.h" - -#include "collection.h" -#include "imapset_p.h" -#include "job_p.h" - -using namespace Akonadi; - -class Akonadi::ItemCopyJobPrivate : public JobPrivate -{ - public: - ItemCopyJobPrivate( ItemCopyJob *parent ) - : JobPrivate( parent ) - { - } - - Item::List mItems; - Collection mTarget; -}; - -ItemCopyJob::ItemCopyJob(const Item & item, const Collection & target, QObject * parent) - : Job( new ItemCopyJobPrivate( this ), parent ) -{ - Q_D( ItemCopyJob ); - - d->mItems << item; - d->mTarget = target; -} - -ItemCopyJob::ItemCopyJob(const Item::List & items, const Collection & target, QObject * parent) - : Job( new ItemCopyJobPrivate( this ), parent ) -{ - Q_D( ItemCopyJob ); - - d->mItems = items; - d->mTarget = target; -} - -ItemCopyJob::~ItemCopyJob() -{ -} - -void ItemCopyJob::doStart() -{ - Q_D( ItemCopyJob ); - - QList ids; - foreach ( const Item &item, d->mItems ) - ids << item.id(); - ImapSet set; - set.add( ids ); - QByteArray cmd( d->newTag() ); - cmd += " COPY "; - cmd += set.toImapSequenceSet(); - cmd += ' '; - cmd += QByteArray::number( d->mTarget.id() ); - cmd += '\n'; - d->writeData( cmd ); -} - -#include "itemcopyjob.moc" diff --git a/akonadi/itemcopyjob.h b/akonadi/itemcopyjob.h deleted file mode 100644 index 09f3ae5fa..000000000 --- a/akonadi/itemcopyjob.h +++ /dev/null @@ -1,91 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_ITEMCOPYJOB_H -#define AKONADI_ITEMCOPYJOB_H - -#include -#include - -namespace Akonadi { - -class Collection; -class ItemCopyJobPrivate; - -/** - * @short Job that copies a set of items to a target collection in the Akonadi storage. - * - * The job can be used to copy one or several Item objects to another collection. - * - * Example: - * - * @code - * - * Akonadi::Item::List items = ... - * Akonadi::Collection collection = ... - * - * Akonadi::ItemCopyJob *job = new Akonadi::ItemCopyJob( items, collection ); - * - * if ( job->exec() ) - * qDebug() << "Items copied successfully"; - * else - * qDebug() << "Error occurred"; - * - * @endcode - * - * @author Volker Krause - */ -class AKONADI_EXPORT ItemCopyJob : public Job -{ - Q_OBJECT - - public: - /** - * Creates a new item copy job. - * - * @param item The item to copy. - * @param target The target collection. - * @param parent The parent object. - */ - ItemCopyJob( const Item &item, const Collection &target, QObject *parent = 0 ); - - /** - * Creates a new item copy job. - * - * @param items A list of items to copy. - * @param target The target collection. - * @param parent The parent object. - */ - ItemCopyJob( const Item::List &items, const Collection &target, QObject *parent = 0 ); - - /** - * Destroys the item copy job. - */ - ~ItemCopyJob(); - - protected: - void doStart(); - - private: - Q_DECLARE_PRIVATE( ItemCopyJob ) -}; - -} - -#endif diff --git a/akonadi/itemcreatejob.cpp b/akonadi/itemcreatejob.cpp deleted file mode 100644 index 0173269bb..000000000 --- a/akonadi/itemcreatejob.cpp +++ /dev/null @@ -1,148 +0,0 @@ -/* - Copyright (c) 2006 - 2007 Volker Krause - Copyright (c) 2007 Robert Zwerus - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "itemcreatejob.h" - -#include "collection.h" -#include "imapparser_p.h" -#include "item.h" -#include "itemserializer.h" -#include "job_p.h" -#include "protocolhelper.h" - -#include - -using namespace Akonadi; - -class Akonadi::ItemCreateJobPrivate : public JobPrivate -{ - public: - ItemCreateJobPrivate( ItemCreateJob *parent ) - : JobPrivate( parent ) - { - } - - Collection mCollection; - Item mItem; - QSet mParts; - Item::Id mUid; - QByteArray mData; -}; - -ItemCreateJob::ItemCreateJob( const Item &item, const Collection &collection, QObject * parent ) - : Job( new ItemCreateJobPrivate( this ), parent ) -{ - Q_D( ItemCreateJob ); - - Q_ASSERT( !item.mimeType().isEmpty() ); - d->mItem = item; - d->mParts = d->mItem.loadedPayloadParts(); - d->mCollection = collection; -} - -ItemCreateJob::~ItemCreateJob() -{ -} - -void ItemCreateJob::doStart() -{ - Q_D( ItemCreateJob ); - - QByteArray remoteId; - - if ( !d->mItem.remoteId().isEmpty() ) - remoteId = ' ' + ImapParser::quote( "\\RemoteId[" + d->mItem.remoteId().toUtf8() + ']' ); - // switch between a normal APPEND and a multipart X-AKAPPEND, based on the number of parts - if ( d->mItem.attributes().isEmpty() && ( d->mParts.isEmpty() || (d->mParts.size() == 1 && d->mParts.contains( Item::FullPayload )) ) ) { - if ( d->mItem.hasPayload() ) { - int version = 0; - ItemSerializer::serialize( d->mItem, Item::FullPayload, d->mData, version ); - } - int dataSize = d->mData.size(); - - d->writeData( d->newTag() + " APPEND " + QByteArray::number( d->mCollection.id() ) - + " (\\MimeType[" + d->mItem.mimeType().toLatin1() + ']' + remoteId + ") {" - + QByteArray::number( dataSize ) + "}\n" ); - } - else { // do a multipart X-AKAPPEND - QByteArray command = d->newTag() + " X-AKAPPEND " + QByteArray::number( d->mCollection.id() ) - + " (\\MimeType[" + d->mItem.mimeType().toLatin1() + ']' + remoteId + ") "; - - QList partSpecs; - int totalSize = 0; - foreach( const QByteArray &partName, d->mParts ) { - QByteArray partData; - int version = 0; - ItemSerializer::serialize( d->mItem, partName, partData, version ); - totalSize += partData.size(); - const QByteArray partId = ProtocolHelper::encodePartIdentifier( ProtocolHelper::PartPayload, partName, version ); - partSpecs.append( ImapParser::quote( partId ) + ':' + QByteArray::number( partData.size() ) ); - d->mData += partData; - } - foreach ( const Attribute* attr, d->mItem.attributes() ) { - const QByteArray data = attr->serialized(); - totalSize += data.size(); - const QByteArray partId = ProtocolHelper::encodePartIdentifier( ProtocolHelper::PartAttribute, attr->type() ); - partSpecs.append( ImapParser::quote( partId ) + ':' + QByteArray::number( data.size() ) ); - d->mData += data; - } - command += '(' + ImapParser::join( partSpecs, "," ) + ") " + - '{' + QByteArray::number( totalSize ) + "}\n"; - - d->writeData( command ); - } -} - -void ItemCreateJob::doHandleResponse( const QByteArray & tag, const QByteArray & data ) -{ - Q_D( ItemCreateJob ); - - if ( tag == "+" ) { // ready for literal data - d->writeData( d->mData ); - if ( !d->mData.endsWith( '\n' ) ) - d->writeData( "\n" ); - return; - } - if ( tag == d->tag() ) { - if ( int pos = data.indexOf( "UIDNEXT" ) ) { - bool ok = false; - ImapParser::parseNumber( data, d->mUid, &ok, pos + 7 ); - if ( !ok ) { - kDebug( 5250 ) << "Invalid UIDNEXT response to APPEND command: " - << tag << data; - } - } - } -} - -Item ItemCreateJob::item() const -{ - Q_D( const ItemCreateJob ); - - if ( d->mUid == 0 ) - return Item(); - - Item item( d->mItem ); - item.setId( d->mUid ); - - return item; -} - -#include "itemcreatejob.moc" diff --git a/akonadi/itemcreatejob.h b/akonadi/itemcreatejob.h deleted file mode 100644 index c7560002b..000000000 --- a/akonadi/itemcreatejob.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - Copyright (c) 2006 - 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_ITEMCREATEJOB_H -#define AKONADI_ITEMCREATEJOB_H - -#include - -namespace Akonadi { - -class Collection; -class Item; -class ItemCreateJobPrivate; - -/** - * @short Job that creates a new item in the Akonadi storage. - * - * This job creates a new item with all the set properties in the - * given target collection. - * - * Example: - * - * @code - * - * // Create a contact item in the root collection - * - * KABC::Addressee addr; - * addr.setNameFromString( "Joe Jr. Miller" ); - * - * Akonadi::Item item; - * item.setMimeType( "text/directory" ); - * item.setPayload( addr ); - * - * Akonadi::Collection collection = Akonadi::Collection::root(); - * - * Akonadi::ItemCreateJob *job = new Akonadi::ItemCreateJob( item, collection ); - * - * if ( job->exec() ) - * qDebug() << "Contact item created successfully"; - * else - * qDebug() << "Error occurred"; - * - * @endcode - * - * @author Volker Krause - */ -class AKONADI_EXPORT ItemCreateJob : public Job -{ - Q_OBJECT - - public: - /** - * Creates a new item create job. - * - * @param item The item to create. - * @note It must have a mime type set. - * @param collection The parent collection where the new item shall be located in. - * @param parent The parent object. - */ - ItemCreateJob( const Item &item, const Collection &collection, QObject *parent = 0 ); - - /** - * Destroys the item create job. - */ - ~ItemCreateJob(); - - /** - * Returns the created item with the new unique id, or an invalid item if the job failed. - */ - Item item() const; - - protected: - virtual void doStart(); - virtual void doHandleResponse( const QByteArray &tag, const QByteArray &data ); - - private: - Q_DECLARE_PRIVATE( ItemCreateJob ) -}; - -} - -#endif diff --git a/akonadi/itemdeletejob.cpp b/akonadi/itemdeletejob.cpp deleted file mode 100644 index 60503705a..000000000 --- a/akonadi/itemdeletejob.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* - Copyright (c) 2006 - 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "itemdeletejob.h" -#include "itemmodifyjob.h" -#include "job_p.h" -#include "transactionjobs.h" -#include "expungejob.h" - -using namespace Akonadi; - -class Akonadi::ItemDeleteJobPrivate : public JobPrivate -{ - public: - enum State { - Begin, - Store, - Expunge, - Commit - }; - - ItemDeleteJobPrivate( ItemDeleteJob *parent ) - : JobPrivate( parent ) - { - } - - void jobDone( KJob* ); - - Q_DECLARE_PUBLIC( ItemDeleteJob ) - - Item mItem; - State mState; -}; - -void ItemDeleteJobPrivate::jobDone( KJob * job ) -{ - Q_Q( ItemDeleteJob ); - - if ( !job->error() ) // error is already handled by KCompositeJob - q->emitResult(); -} - -ItemDeleteJob::ItemDeleteJob( const Item & item, QObject * parent ) - : Job( new ItemDeleteJobPrivate( this ), parent ) -{ - Q_D( ItemDeleteJob ); - - d->mItem = item; - d->mState = ItemDeleteJobPrivate::Begin; -} - -ItemDeleteJob::~ItemDeleteJob() -{ -} - -void ItemDeleteJob::doStart() -{ - Q_D( ItemDeleteJob ); - - TransactionBeginJob *begin = new TransactionBeginJob( this ); - addSubjob( begin ); - - d->mItem.setFlag( "\\Deleted" ); - ItemModifyJob* store = new ItemModifyJob( d->mItem, this ); - store->disableRevisionCheck(); - addSubjob( store ); - - ExpungeJob *expunge = new ExpungeJob( this ); - addSubjob( expunge ); - - TransactionCommitJob *commit = new TransactionCommitJob( this ); - connect( commit, SIGNAL(result(KJob*)), SLOT(jobDone(KJob*)) ); - addSubjob( commit ); -} - -#include "itemdeletejob.moc" diff --git a/akonadi/itemdeletejob.h b/akonadi/itemdeletejob.h deleted file mode 100644 index 66bbe9068..000000000 --- a/akonadi/itemdeletejob.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_ITEMDELETEJOB_H -#define AKONADI_ITEMDELETEJOB_H - -#include "akonadi_export.h" - -#include - -namespace Akonadi { - -class Item; -class ItemDeleteJobPrivate; - -/** - * @short Job that deletes an item from the Akonadi storage. - * - * This job removes the given item from the Akonadi storage. - * - * Example: - * - * @code - * - * Akonadi::Item item = ... - * - * ItemDeleteJob *job = new ItemDeleteJob( item ); - * - * if ( job->exec() ) - * qDebug() << "Item deleted successfully"; - * else - * qDebug() << "Error occurred"; - * - * @endcode - * - * @author Volker Krause - */ -class AKONADI_EXPORT ItemDeleteJob : public Job -{ - Q_OBJECT - - public: - /** - * Creates a new item delete job. - * - * @param item The item to delete. - * @param parent The parent object. - */ - explicit ItemDeleteJob( const Item &item, QObject *parent = 0 ); - - /** - * Destroys the item delete job. - */ - ~ItemDeleteJob(); - - protected: - virtual void doStart(); - - private: - Q_DECLARE_PRIVATE( ItemDeleteJob ) - - //@cond PRIVATE - Q_PRIVATE_SLOT( d_func(), void jobDone( KJob* ) ) - //@endcond -}; - -} - -#endif diff --git a/akonadi/itemfetchjob.cpp b/akonadi/itemfetchjob.cpp deleted file mode 100644 index f9f9a6590..000000000 --- a/akonadi/itemfetchjob.cpp +++ /dev/null @@ -1,271 +0,0 @@ -/* - Copyright (c) 2006 - 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "itemfetchjob.h" - -#include "attributefactory.h" -#include "collection.h" -#include "collectionselectjob.h" -#include "imapparser_p.h" -#include "itemfetchscope.h" -#include "itemserializer.h" -#include "itemserializerplugin.h" -#include "job_p.h" -#include "entity_p.h" -#include "protocol_p.h" -#include "protocolhelper.h" - -#include - -#include -#include - -using namespace Akonadi; - -class Akonadi::ItemFetchJobPrivate : public JobPrivate -{ - public: - ItemFetchJobPrivate( ItemFetchJob *parent ) - : JobPrivate( parent ) - { - } - - void timeout() - { - Q_Q( ItemFetchJob ); - - mEmitTimer->stop(); // in case we are called by result() - if ( !mPendingItems.isEmpty() ) { - emit q->itemsReceived( mPendingItems ); - mPendingItems.clear(); - } - } - - void startFetchJob(); - void selectDone( KJob * job ); - - Q_DECLARE_PUBLIC( ItemFetchJob ) - - Collection mCollection; - Item mItem; - Item::List mItems; - ItemFetchScope mFetchScope; - Item::List mPendingItems; // items pending for emitting itemsReceived() - QTimer* mEmitTimer; -}; - -void ItemFetchJobPrivate::startFetchJob() -{ - QByteArray command = newTag(); - if ( !mItem.isValid() ) - command += " " AKONADI_CMD_ITEMFETCH " 1:*"; - else - command += " " AKONADI_CMD_UID " " AKONADI_CMD_ITEMFETCH " " + QByteArray::number( mItem.id() ); - - if ( mFetchScope.fullPayload() ) - command += " " AKONADI_PARAM_FULLPAYLOAD; - if ( mFetchScope.allAttributes() ) - command += " " AKONADI_PARAM_ALLATTRIBUTES; - if ( mFetchScope.cacheOnly() ) - command += " " AKONADI_PARAM_CACHEONLY; - - command += " (UID REMOTEID FLAGS"; - foreach ( const QByteArray &part, mFetchScope.payloadParts() ) - command += ' ' + ProtocolHelper::encodePartIdentifier( ProtocolHelper::PartPayload, part ); - foreach ( const QByteArray &part, mFetchScope.attributes() ) - command += ' ' + ProtocolHelper::encodePartIdentifier( ProtocolHelper::PartAttribute, part ); - command += ")\n"; - - writeData( command ); -} - -void ItemFetchJobPrivate::selectDone( KJob * job ) -{ - if ( !job->error() ) - // the collection is now selected, fetch the message(s) - startFetchJob(); -} - -ItemFetchJob::ItemFetchJob( const Collection &collection, QObject * parent ) - : Job( new ItemFetchJobPrivate( this ), parent ) -{ - Q_D( ItemFetchJob ); - - d->mEmitTimer = new QTimer( this ); - d->mEmitTimer->setSingleShot( true ); - d->mEmitTimer->setInterval( 100 ); - connect( d->mEmitTimer, SIGNAL(timeout()), this, SLOT(timeout()) ); - connect( this, SIGNAL(result(KJob*)), this, SLOT(timeout()) ); - - d->mCollection = collection; -} - -ItemFetchJob::ItemFetchJob( const Item & item, QObject * parent) - : Job( new ItemFetchJobPrivate( this ), parent ) -{ - Q_D( ItemFetchJob ); - - d->mEmitTimer = new QTimer( this ); - d->mEmitTimer->setSingleShot( true ); - d->mEmitTimer->setInterval( 100 ); - connect( d->mEmitTimer, SIGNAL(timeout()), this, SLOT(timeout()) ); - connect( this, SIGNAL(result(KJob*)), this, SLOT(timeout()) ); - - d->mCollection = Collection::root(); - d->mItem = item; -} - -ItemFetchJob::~ItemFetchJob() -{ -} - -void ItemFetchJob::doStart() -{ - Q_D( ItemFetchJob ); - - if ( !d->mItem.isValid() ) { // collection content listing - if ( d->mCollection == Collection::root() ) { - setErrorText( QLatin1String("Cannot list root collection.") ); - setError( Unknown ); - emitResult(); - } - CollectionSelectJob *job = new CollectionSelectJob( d->mCollection, this ); - connect( job, SIGNAL(result(KJob*)), SLOT(selectDone(KJob*)) ); - addSubjob( job ); - } else - d->startFetchJob(); -} - -void ItemFetchJob::doHandleResponse( const QByteArray & tag, const QByteArray & data ) -{ - Q_D( ItemFetchJob ); - - if ( tag == "*" ) { - int begin = data.indexOf( "FETCH" ); - if ( begin >= 0 ) { - - // split fetch response into key/value pairs - QList fetchResponse; - ImapParser::parseParenthesizedList( data, fetchResponse, begin + 6 ); - - // create a new item object - Item::Id uid = -1; - int rev = -1; - QString rid; - QString mimeType; - - for ( int i = 0; i < fetchResponse.count() - 1; i += 2 ) { - const QByteArray key = fetchResponse.value( i ); - const QByteArray value = fetchResponse.value( i + 1 ); - - if ( key == "UID" ) - uid = value.toLongLong(); - else if ( key == "REV" ) - rev = value.toInt(); - else if ( key == "REMOTEID" ) - rid = QString::fromUtf8( value ); - else if ( key == "MIMETYPE" ) - mimeType = QString::fromLatin1( value ); - } - - if ( uid < 0 || rev < 0 || mimeType.isEmpty() ) { - kWarning( 5250 ) << "Broken fetch response: UID, RID, REV or MIMETYPE missing!"; - return; - } - - Item item( uid ); - item.setRemoteId( rid ); - item.setRevision( rev ); - item.setMimeType( mimeType ); - if ( !item.isValid() ) - return; - - // parse fetch response fields - for ( int i = 0; i < fetchResponse.count() - 1; i += 2 ) { - const QByteArray key = fetchResponse.value( i ); - // skip stuff we dealt with already - if ( key == "UID" || key == "REV" || key == "REMOTEID" || key == "MIMETYPE" ) - continue; - // flags - if ( key == "FLAGS" ) { - QList flags; - ImapParser::parseParenthesizedList( fetchResponse[i + 1], flags ); - foreach ( const QByteArray &flag, flags ) { - item.setFlag( flag ); - } - } else { - int version = 0; - QByteArray plainKey( key ); - ProtocolHelper::PartNamespace ns; - - ImapParser::splitVersionedKey( key, plainKey, version ); - plainKey = ProtocolHelper::decodePartIdentifier( plainKey, ns ); - - switch ( ns ) { - case ProtocolHelper::PartPayload: - ItemSerializer::deserialize( item, plainKey, fetchResponse.value( i + 1 ), version ); - break; - case ProtocolHelper::PartAttribute: - { - Attribute* attr = AttributeFactory::createAttribute( plainKey ); - Q_ASSERT( attr ); - attr->deserialize( fetchResponse.value( i + 1 ) ); - item.addAttribute( attr ); - break; - } - case ProtocolHelper::PartGlobal: - default: - kWarning() << "Unknown item part type:" << key; - } - } - } - - item.d_ptr->resetChangeLog(); - d->mItems.append( item ); - d->mPendingItems.append( item ); - if ( !d->mEmitTimer->isActive() ) - d->mEmitTimer->start(); - return; - } - } - kDebug( 5250 ) << "Unhandled response: " << tag << data; -} - -Item::List ItemFetchJob::items() const -{ - Q_D( const ItemFetchJob ); - - return d->mItems; -} - -void ItemFetchJob::setFetchScope( ItemFetchScope &fetchScope ) -{ - Q_D( ItemFetchJob ); - - d->mFetchScope = fetchScope; -} - -ItemFetchScope &ItemFetchJob::fetchScope() -{ - Q_D( ItemFetchJob ); - - return d->mFetchScope; -} - -#include "itemfetchjob.moc" diff --git a/akonadi/itemfetchjob.h b/akonadi/itemfetchjob.h deleted file mode 100644 index de81ce289..000000000 --- a/akonadi/itemfetchjob.h +++ /dev/null @@ -1,143 +0,0 @@ -/* - Copyright (c) 2006 - 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_ITEMFETCHJOB_H -#define AKONADI_ITEMFETCHJOB_H - -#include -#include - -namespace Akonadi { - -class Collection; -class ItemFetchJobPrivate; -class ItemFetchScope; - -/** - * @short Job that fetches items from the Akonadi storage. - * - * This class is used to fetch items from the Akonadi storage. - * Which parts of the items (e.g. headers only, attachments or all) - * can be specified by the ItemFetchScope. - * - * Example: - * - * @code - * - * // Fetch all items with full payload from the root collection - * Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob( Akonadi::Collection::root() ); - * job->fetchScope().fetchFullPayload(); - * - * if ( job->exec() ) { - * Akonadi::Item::List items = job->items(); - * foreach( const Akonadi::Item &item, items ) { - * qDebug() "Item ID:" << item.id(); - * } - * } else { - * qDebug() << "Error occurred"; - * } - * - * @endcode - * - * @author Volker Krause - */ -class AKONADI_EXPORT ItemFetchJob : public Job -{ - Q_OBJECT - public: - /** - * Creates a new item fetch job. - * - * @param collection The parent collection to fetch all items from. - * @param parent The parent object. - */ - explicit ItemFetchJob( const Collection &collection, QObject *parent = 0 ); - - /** - * Creates a new item fetch job. - * - * @param item The item to fetch. - * @param parent The parent object. - */ - explicit ItemFetchJob( const Item &item, QObject *parent = 0 ); - - /** - * Destroys the item fetch job. - */ - virtual ~ItemFetchJob(); - - /** - * Returns the fetched item. - * - * @note The items are invalid before the result( KJob* ) - * signal has been emitted or if an error occurred. - */ - Item::List items() const; - - /** - * Sets the item fetch scope. - * - * The ItemFetchScope controls how much of an item's data is fetched - * from the server, e.g. whether to fetch the full item payload or - * only meta data. - * - * @param fetchScope The new scope for item fetch operations. - * - * @see fetchScope() - */ - void setFetchScope( ItemFetchScope &fetchScope ); - - /** - * Returns the item fetch scope. - * - * Since this returns a reference it can be used to conveniently modify the - * current scope in-place, i.e. by calling a method on the returned reference - * without storing it in a local variable. See the ItemFetchScope documentation - * for an example. - * - * @return a reference to the current item fetch scope - * - * @see setFetchScope() for replacing the current item fetch scope - */ - ItemFetchScope &fetchScope(); - - Q_SIGNALS: - /** - * This signal is emitted when the items are fetched completely. - * - * @param items The fetched items. - */ - void itemsReceived( const Akonadi::Item::List &items ); - - protected: - virtual void doStart(); - virtual void doHandleResponse( const QByteArray &tag, const QByteArray &data ); - - private: - Q_DECLARE_PRIVATE( ItemFetchJob ) - - //@cond PRIVATE - Q_PRIVATE_SLOT( d_func(), void selectDone( KJob* ) ) - Q_PRIVATE_SLOT( d_func(), void timeout() ) - //@endcond -}; - -} - -#endif diff --git a/akonadi/itemfetchscope.cpp b/akonadi/itemfetchscope.cpp deleted file mode 100644 index 087b48e03..000000000 --- a/akonadi/itemfetchscope.cpp +++ /dev/null @@ -1,109 +0,0 @@ -/* - Copyright (c) 2008 Kevin Krammer - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "itemfetchscope.h" - -#include "itemfetchscope_p.h" - -#include - -using namespace Akonadi; - -ItemFetchScope::ItemFetchScope() -{ - d = new ItemFetchScopePrivate(); -} - -ItemFetchScope::ItemFetchScope( const ItemFetchScope &other ) - : d( other.d ) -{ -} - -ItemFetchScope::~ItemFetchScope() -{ -} - -ItemFetchScope &ItemFetchScope::operator=( const ItemFetchScope &other ) -{ - if ( &other != this ) - d = other.d; - - return *this; -} - -QSet< QByteArray > ItemFetchScope::payloadParts() const -{ - return d->mPayloadParts; -} - -void ItemFetchScope::fetchPayloadPart(const QByteArray & part, bool fetch) -{ - if ( fetch ) - d->mPayloadParts.insert( part ); - else - d->mPayloadParts.remove( part ); -} - -bool ItemFetchScope::fullPayload() const -{ - return d->mFullPayload; -} - -void ItemFetchScope::fetchFullPayload(bool fetch) -{ - d->mFullPayload = fetch; -} - -QSet< QByteArray > ItemFetchScope::attributes() const -{ - return d->mAttributes; -} - -void ItemFetchScope::fetchAttribute(const QByteArray & type, bool fetch) -{ - if ( fetch ) - d->mAttributes.insert( type ); - else - d->mAttributes.remove( type ); -} - -bool ItemFetchScope::allAttributes() const -{ - return d->mAllAttributes; -} - -void ItemFetchScope::fetchAllAttributes(bool fetch) -{ - d->mAllAttributes = fetch; -} - -bool ItemFetchScope::isEmpty() const -{ - return d->mPayloadParts.isEmpty() && d->mAttributes.isEmpty() && !d->mFullPayload && !d->mAllAttributes; -} - -bool ItemFetchScope::cacheOnly() const -{ - return d->mCacheOnly; -} - -void ItemFetchScope::setCacheOnly(bool cacheOnly) -{ - d->mCacheOnly = cacheOnly; -} diff --git a/akonadi/itemfetchscope.h b/akonadi/itemfetchscope.h deleted file mode 100644 index 4c2f6f836..000000000 --- a/akonadi/itemfetchscope.h +++ /dev/null @@ -1,195 +0,0 @@ -/* - Copyright (c) 2008 Kevin Krammer - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef ITEMFETCHSCOPE_H -#define ITEMFETCHSCOPE_H - -#include "akonadi_export.h" - -#include - -class QStringList; -template class QSet; - -namespace Akonadi { - -class ItemFetchScopePrivate; - -/** - * @short Specifies which parts of an item should be fetched from the Akonadi storage. - * - * When items are fetched from server either by using ItemFetchJob explicitly or - * when it is being used internally by other classes, e.g. ItemModel, the scope - * of the fetch operation can be tailored to the application's current needs. - * - * There are two supported ways of changing the currently active ItemFetchScope - * of classes: - * - in-place: modify the ItemFetchScope object the other class holds as a member - * - replace: replace the other class' member with a new scope object - * - * Example: modifying an ItemFetchJob's scope @c in-place - * @code - * Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob( collection ); - * job->fetchScope().fetchFullPayload(); - * job->fetchScope().fetchAttribute(); - * @endcode - * - * Example: @c replacing an ItemFetchJob's scope - * @code - * Akonadi::ItemFetchScope scope; - * scope.fetchFullPayload(); - * scope.fetchAttribute(); - * - * Akonadi::ItemFetchJob *job = new Akonadi::ItemFetchJob( collection ); - * job->setFetchScope( scope ); - * @endcode - * - * This class is implicitly shared. - * - * @author Kevin Krammer - */ -class AKONADI_EXPORT ItemFetchScope -{ - public: - /** - * Creates an empty item fetch scope. - * - * Using an empty scope will only fetch the very basic meta data of items, - * e.g. local id, remote id and mime type - */ - ItemFetchScope(); - - /** - * Creates a new item fetch scope from an @p other. - */ - ItemFetchScope( const ItemFetchScope &other ); - - /** - * Destroys the item fetch scope. - */ - ~ItemFetchScope(); - - /** - * Assigns the @p other to this scope and returns a reference to this scope. - */ - ItemFetchScope &operator=( const ItemFetchScope &other ); - - /** - * Returns the payload parts that should be fetched. - * - * @see fetchPayloadPart() - */ - QSet payloadParts() const; - - /** - * Sets which payload parts shall be fetched. - * - * @param part The payload part identifier. - * Valid values depend on the item type. - * @param fetch @c true to fetch this part, @c false otherwise. - */ - void fetchPayloadPart( const QByteArray &part, bool fetch = true ); - - /** - * Returns whether the full payload should be fetched. - * - * @see fetchFullPayload() - */ - bool fullPayload() const; - - /** - * Sets whether the full payload shall be fetched. - * - * @param fetch @c true if the full payload should be fetched, @c false otherwise. - */ - void fetchFullPayload( bool fetch = true ); - - /** - * Returns all explicitly fetched attributes. - * - * Undefined if fetchAllAttributes() returns true. - * - * @see fetchAttribute() - */ - QSet attributes() const; - - /** - * Sets whether the attribute of the given @p type should be fetched. - * - * @param type The attribute type to fetch. - * @param fetch @c true if the attribute should be fetched, @c false otherwise. - */ - void fetchAttribute( const QByteArray &type, bool fetch = true ); - - /** - * Sets whether the attribute of the requested type should be fetched. - * - * @param fetch @c true if the attribute should be fetched, @c false otherwise. - */ - template inline void fetchAttribute( bool fetch = true ) - { - T dummy; - fetchAttribute( dummy.type(), fetch ); - } - - /** - * Returns whether all available attributes should be fetched. - * - * @see fetchAllAttributes() - */ - bool allAttributes() const; - - /** - * Sets whether all available attributes should be fetched. - * - * @param fetch @c true if all available attributes should be fetched, @c false otherwise. - */ - void fetchAllAttributes( bool fetch = true ); - - /** - * Returns whether payload data should be requested from remote sources or just - * from the local cache. - * - * @see setCacheOnly() - */ - bool cacheOnly() const; - - /** - * Sets whether payload data should be requested from remote sources or just - * from the local cache. - * - * @param cacheOnly @c true if no remote data should be requested, - * @c false otherwise (the default). - */ - void setCacheOnly( bool cacheOnly ); - - /** - * Returns @c true if there is nothing to fetch. - */ - bool isEmpty() const; - - private: - //@cond PRIVATE - QSharedDataPointer d; - //@endcond -}; - -} - -#endif diff --git a/akonadi/itemfetchscope_p.h b/akonadi/itemfetchscope_p.h deleted file mode 100644 index 32188762c..000000000 --- a/akonadi/itemfetchscope_p.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - Copyright (c) 2008 Kevin Krammer - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef ITEMFETCHSCOPE_P_H -#define ITEMFETCHSCOPE_P_H - -#include -#include - -namespace Akonadi { - -/** - * @internal - */ -class ItemFetchScopePrivate : public QSharedData -{ - public: - ItemFetchScopePrivate() - : mFullPayload( false ), - mAllAttributes( false ), - mCacheOnly( false ) - { - } - - ItemFetchScopePrivate( const ItemFetchScopePrivate &other ) - : QSharedData( other ) - { - mPayloadParts = other.mPayloadParts; - mAttributes = other.mAttributes; - mFullPayload = other.mFullPayload; - mAllAttributes = other.mAllAttributes; - mCacheOnly = other.mCacheOnly; - } - - public: - QSet mPayloadParts; - QSet mAttributes; - bool mFullPayload; - bool mAllAttributes; - bool mCacheOnly; -}; - -} - -#endif diff --git a/akonadi/itemmodel.cpp b/akonadi/itemmodel.cpp deleted file mode 100644 index 5e63d3dd3..000000000 --- a/akonadi/itemmodel.cpp +++ /dev/null @@ -1,397 +0,0 @@ -/* - Copyright (c) 2006 - 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "itemmodel.h" - -#include "itemfetchjob.h" -#include "itemfetchscope.h" -#include "monitor.h" -#include "pastehelper.h" -#include "session.h" - -#include - -#include -#include -#include - -#include -#include - -using namespace Akonadi; - -/** - * @internal - * - * This struct is used for optimization reasons. - * because it embeds the row. - * - * Semantically, we could have used an item instead. - */ -struct ItemContainer -{ - ItemContainer( const Item& i, int r ) - { - item = i; - row = r; - } - Item item; - int row; -}; - -/** - * @internal - */ -class ItemModel::Private -{ - public: - Private( ItemModel *parent ) - : mParent( parent ), monitor( new Monitor() ) - { - session = new Session( QByteArray("ItemModel-") + QByteArray::number( qrand() ), mParent ); - - monitor->ignoreSession( session ); - - mParent->connect( monitor, SIGNAL(itemChanged( const Akonadi::Item&, const QSet& )), - mParent, SLOT(itemChanged( const Akonadi::Item&, const QSet& )) ); - mParent->connect( monitor, SIGNAL(itemMoved( const Akonadi::Item&, const Akonadi::Collection&, const Akonadi::Collection& )), - mParent, SLOT(itemMoved( const Akonadi::Item&, const Akonadi::Collection&, const Akonadi::Collection& ) ) ); - mParent->connect( monitor, SIGNAL(itemAdded( const Akonadi::Item&, const Akonadi::Collection& )), - mParent, SLOT(itemAdded( const Akonadi::Item& )) ); - mParent->connect( monitor, SIGNAL(itemRemoved(Akonadi::Item)), - mParent, SLOT(itemRemoved(Akonadi::Item)) ); - } - - ~Private() - { - delete monitor; - } - - void listingDone( KJob* ); - void itemChanged( const Akonadi::Item&, const QSet& ); - void itemsAdded( const Akonadi::Item::List &list ); - void itemAdded( const Akonadi::Item &item ); - void itemMoved( const Akonadi::Item&, const Akonadi::Collection& src, const Akonadi::Collection& dst ); - void itemRemoved( const Akonadi::Item& ); - int rowForItem( const Akonadi::Item& ); - - ItemModel *mParent; - - QList items; - QHash itemHash; - - Collection collection; - Monitor *monitor; - Session *session; -}; - -void ItemModel::Private::listingDone( KJob * job ) -{ - ItemFetchJob *fetch = static_cast( job ); - Q_UNUSED( fetch ); - if ( job->error() ) { - // TODO - kWarning( 5250 ) << "Item query failed:" << job->errorString(); - } -} - -int ItemModel::Private::rowForItem( const Akonadi::Item& item ) -{ - ItemContainer *container = itemHash.value( item ); - if ( !container ) - return -1; - - /* Try to find the item directly; - - If items have been removed, this first try won't succeed because - the ItemContainer rows have not been updated (costs too much). - */ - if ( container->row < items.count() - && items.at( container->row ) == container ) - return container->row; - else { // Slow solution if the fist one has not succeeded - int row = -1; - for ( int i = 0; i < items.size(); ++i ) { - if ( items.at( i )->item == item ) { - row = i; - break; - } - } - return row; - } - -} - -void ItemModel::Private::itemChanged( const Akonadi::Item &item, const QSet& ) -{ - int row = rowForItem( item ); - if ( row < 0 ) - return; - - items[ row ]->item = item; - itemHash.remove( item ); - itemHash[ item ] = items[ row ]; - - QModelIndex start = mParent->index( row, 0, QModelIndex() ); - QModelIndex end = mParent->index( row, mParent->columnCount( QModelIndex() ) - 1 , QModelIndex() ); - - mParent->dataChanged( start, end ); -} - -void ItemModel::Private::itemMoved( const Akonadi::Item &item, const Akonadi::Collection& colSrc, const Akonadi::Collection& colDst ) -{ - if ( colSrc == collection && colDst != collection ) // item leaving this model - { - itemRemoved( item ); - return; - } - - - if ( colDst == collection && colSrc != collection ) - { - itemAdded( item ); - return; - } -} - -void ItemModel::Private::itemsAdded( const Akonadi::Item::List &list ) -{ - if ( list.isEmpty() ) - return; - mParent->beginInsertRows( QModelIndex(), items.count(), items.count() + list.count() - 1 ); - foreach( const Item &item, list ) { - ItemContainer *c = new ItemContainer( item, items.count() ); - items.append( c ); - itemHash[ item ] = c; - } - mParent->endInsertRows(); -} - -void ItemModel::Private::itemAdded( const Akonadi::Item &item ) -{ - Item::List l; - l << item; - itemsAdded( l ); -} - -void ItemModel::Private::itemRemoved( const Akonadi::Item &_item ) -{ - int row = rowForItem( _item ); - if ( row < 0 ) - return; - - mParent->beginRemoveRows( QModelIndex(), row, row ); - const Item item = items.at( row )->item; - Q_ASSERT( item.isValid() ); - itemHash.remove( item ); - delete items.takeAt( row ); - mParent->endRemoveRows(); -} - -ItemModel::ItemModel( QObject *parent ) : - QAbstractTableModel( parent ), - d( new Private( this ) ) -{ - setSupportedDragActions( Qt::MoveAction | Qt::CopyAction ); -} - -ItemModel::~ItemModel() -{ - delete d; -} - -QVariant ItemModel::data( const QModelIndex & index, int role ) const -{ - if ( !index.isValid() ) - return QVariant(); - if ( index.row() >= d->items.count() ) - return QVariant(); - const Item item = d->items.at( index.row() )->item; - if ( !item.isValid() ) - return QVariant(); - - if ( role == Qt::DisplayRole ) { - switch ( index.column() ) { - case Id: - return QString::number( item.id() ); - case RemoteId: - return item.remoteId(); - case MimeType: - return item.mimeType(); - default: - return QVariant(); - } - } - - if ( role == IdRole ) - return item.id(); - - if ( role == ItemRole ) { - QVariant var; - var.setValue( item ); - return var; - } - - if ( role == MimeTypeRole ) - return item.mimeType(); - - return QVariant(); -} - -int ItemModel::rowCount( const QModelIndex & parent ) const -{ - if ( !parent.isValid() ) - return d->items.count(); - return 0; -} - -int ItemModel::columnCount(const QModelIndex & parent) const -{ - if ( !parent.isValid() ) - return 3; // keep in sync with Column enum - return 0; -} - -QVariant ItemModel::headerData( int section, Qt::Orientation orientation, int role ) const -{ - if ( orientation == Qt::Horizontal && role == Qt::DisplayRole ) { - switch ( section ) { - case Id: - return i18n( "Id" ); - case RemoteId: - return i18n( "Remote Id" ); - case MimeType: - return i18n( "MimeType" ); - default: - return QString(); - } - } - return QAbstractTableModel::headerData( section, orientation, role ); -} - -void ItemModel::setCollection( const Collection &collection ) -{ - kDebug( 5250 ); - if ( d->collection == collection ) - return; - - d->monitor->setCollectionMonitored( d->collection, false ); - - d->collection = collection; - - d->monitor->setCollectionMonitored( d->collection, true ); - - // the query changed, thus everything we have already is invalid - qDeleteAll( d->items ); - d->items.clear(); - reset(); - - // stop all running jobs - d->session->clear(); - - // start listing job - ItemFetchJob* job = new ItemFetchJob( collection, session() ); - job->setFetchScope( d->monitor->itemFetchScope() ); - connect( job, SIGNAL(itemsReceived(Akonadi::Item::List)), SLOT(itemsAdded(Akonadi::Item::List)) ); - connect( job, SIGNAL(result(KJob*)), SLOT(listingDone(KJob*)) ); - - emit collectionChanged( collection ); -} - -void ItemModel::setFetchScope( const ItemFetchScope &fetchScope ) -{ - d->monitor->setItemFetchScope( fetchScope ); -} - -ItemFetchScope &ItemModel::fetchScope() -{ - return d->monitor->itemFetchScope(); -} - -Item ItemModel::itemForIndex( const QModelIndex & index ) const -{ - if ( !index.isValid() ) - return Akonadi::Item(); - - if ( index.row() >= d->items.count() ) - return Akonadi::Item(); - - Item item = d->items.at( index.row() )->item; - Q_ASSERT( item.isValid() ); - - return item; -} - -Qt::ItemFlags ItemModel::flags( const QModelIndex &index ) const -{ - Qt::ItemFlags defaultFlags = QAbstractTableModel::flags(index); - - if (index.isValid()) - return Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled | defaultFlags; - else - return Qt::ItemIsDropEnabled | defaultFlags; -} - -QStringList ItemModel::mimeTypes() const -{ - return QStringList(); -} - -Session * ItemModel::session() const -{ - return d->session; -} - -QMimeData *ItemModel::mimeData( const QModelIndexList &indexes ) const -{ - QMimeData *data = new QMimeData(); - // Add item uri to the mimedata for dropping in external applications - KUrl::List urls; - foreach ( const QModelIndex &index, indexes ) { - if ( index.column() != 0 ) - continue; - - urls << itemForIndex( index ).url( Item::UrlWithMimeType ); - } - urls.populateMimeData( data ); - - return data; -} - -QModelIndex ItemModel::indexForItem( const Akonadi::Item &item, const int column ) const -{ - return index( d->rowForItem( item ), column ); -} - -bool ItemModel::dropMimeData(const QMimeData * data, Qt::DropAction action, int row, int column, const QModelIndex & parent) -{ - Q_UNUSED( row ); - Q_UNUSED( column ); - Q_UNUSED( parent ); - KJob* job = PasteHelper::paste( data, d->collection, action != Qt::MoveAction ); - // TODO: error handling - return job; -} - -Collection ItemModel::collection() const -{ - return d->collection; -} - -#include "itemmodel.moc" diff --git a/akonadi/itemmodel.h b/akonadi/itemmodel.h deleted file mode 100644 index 8435a6145..000000000 --- a/akonadi/itemmodel.h +++ /dev/null @@ -1,191 +0,0 @@ -/* - Copyright (c) 2006 - 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_ITEMMODEL_H -#define AKONADI_ITEMMODEL_H - -#include "akonadi_export.h" -#include -#include - -#include - -namespace Akonadi { - -class Collection; -class ItemFetchScope; -class Job; -class Session; - -/** - * @short A table model for items. - * - * A self-updating table model that shows all items of - * a collection. - * - * @code - * - * QTableView *view = new QTableView( this ); - * - * Akonadi::ItemModel *model = new Akonadi::ItemModel(); - * view->setModel( model ); - * - * model->setCollection( Akonadi::Collection::root() ); - * - * @endcode - * - * @author Volker Krause - */ -class AKONADI_EXPORT ItemModel : public QAbstractTableModel -{ - Q_OBJECT - - public: - /** - * Describes the types of the columns in the model. - */ - enum Column { - Id = 0, ///< The unique id. - RemoteId, ///< The remote identifier. - MimeType ///< The item's mime type. - }; - - /** - * Describes the roles of the model. - */ - enum Roles { - IdRole = Qt::UserRole + 1, ///< The id of the item. - ItemRole, ///< The item object. - MimeTypeRole, ///< The mime type of the item. - UserRole = Qt::UserRole + 42 ///< Role for user extensions. - }; - - /** - * Creates a new item model. - * - * @param parent The parent object. - */ - explicit ItemModel( QObject* parent = 0 ); - - /** - * Destroys the item model. - */ - virtual ~ItemModel(); - - virtual int columnCount( const QModelIndex & parent = QModelIndex() ) const; - - virtual QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) const; - - virtual int rowCount( const QModelIndex & parent = QModelIndex() ) const; - - virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; - - virtual Qt::ItemFlags flags( const QModelIndex &index ) const; - - virtual QMimeData *mimeData( const QModelIndexList &indexes ) const; - - virtual QStringList mimeTypes() const; - - /** - * Sets the item fetch scope. - * - * The ItemFetchScope controls how much of an item's data is fetched from the - * server, e.g. whether to fetch the full item payload or only meta data. - * - * @param fetchScope The new scope for item fetch operations. - * - * @see fetchScope() - */ - void setFetchScope( const ItemFetchScope &fetchScope ); - - /** - * Returns the item fetch scope. - * - * Since this returns a reference it can be used to conveniently modify the - * current scope in-place, i.e. by calling a method on the returned reference - * without storing it in a local variable. See the ItemFetchScope documentation - * for an example. - * - * @return a reference to the current item fetch scope. - * - * @see setFetchScope() for replacing the current item fetch scope. - */ - ItemFetchScope &fetchScope(); - - /** - * Returns the item at the given @p index. - */ - Item itemForIndex( const QModelIndex &index ) const; - - /** - * Returns the model index for the given item, with the given column. - * - * @param item The item to find. - * @param column The column for the returned index. - */ - QModelIndex indexForItem( const Akonadi::Item& item, const int column ) const; - - bool dropMimeData( const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent ); - - /** - * Returns the collection being displayed in the model. - */ - Collection collection() const; - - public Q_SLOTS: - /** - * Sets the collection the model should display. If the collection has - * changed, the model is reset and a new message listing is requested - * from the Akonadi storage. - * - * @param collection The collection. - */ - void setCollection( const Akonadi::Collection &collection ); - - Q_SIGNALS: - /** - * This signal is emitted whenever setCollection is called. - * - * @param collection The new collection. - */ - void collectionChanged( const Collection &collection ); - - protected: - /** - * Returns the Session object used for all operations by this model. - */ - Session* session() const; - - private: - //@cond PRIVATE - class Private; - Private* const d; - - Q_PRIVATE_SLOT( d, void listingDone( KJob* ) ) - Q_PRIVATE_SLOT( d, void itemChanged( const Akonadi::Item&, const QSet& ) ) - Q_PRIVATE_SLOT( d, void itemMoved( const Akonadi::Item&, const Akonadi::Collection&, const Akonadi::Collection& ) ) - Q_PRIVATE_SLOT( d, void itemAdded( const Akonadi::Item& ) ) - Q_PRIVATE_SLOT( d, void itemsAdded( const Akonadi::Item::List& ) ) - Q_PRIVATE_SLOT( d, void itemRemoved( const Akonadi::Item& ) ) - //@endcond -}; - -} - -#endif diff --git a/akonadi/itemmodifyjob.cpp b/akonadi/itemmodifyjob.cpp deleted file mode 100644 index 38ed5b082..000000000 --- a/akonadi/itemmodifyjob.cpp +++ /dev/null @@ -1,212 +0,0 @@ -/* - Copyright (c) 2006 - 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "itemmodifyjob.h" -#include "itemmodifyjob_p.h" - -#include "collection.h" -#include "entity_p.h" -#include "imapparser_p.h" -#include "itemserializer.h" -#include "job_p.h" -#include "item_p.h" -#include "protocolhelper.h" - -#include - -using namespace Akonadi; - -ItemModifyJobPrivate::ItemModifyJobPrivate( ItemModifyJob *parent, const Item &item ) - : JobPrivate( parent ), - mItem( item ), - mRevCheck( true ), - mIgnorePayload( false ) -{ - mParts = mItem.loadedPayloadParts(); -} - -void ItemModifyJobPrivate::setClean() -{ - mOperations.insert( Dirty ); -} - -QByteArray ItemModifyJobPrivate::nextPartHeader() -{ - QByteArray command; - if ( !mParts.isEmpty() ) { - QSetIterator it( mParts ); - const QByteArray label = it.next(); - mParts.remove( label ); - - mPendingData.clear(); - int version = 0; - ItemSerializer::serialize( mItem, label, mPendingData, version ); - command += ' ' + ProtocolHelper::encodePartIdentifier( ProtocolHelper::PartPayload, label, version ); - command += ".SILENT {" + QByteArray::number( mPendingData.size() ) + '}'; - if ( mPendingData.size() > 0 ) - command += '\n'; - else - command += nextPartHeader(); - } else { - command += ")\n"; - } - return command; -} - - -ItemModifyJob::ItemModifyJob( const Item &item, QObject * parent ) - : Job( new ItemModifyJobPrivate( this, item ), parent ) -{ - Q_D( ItemModifyJob ); - - d->mOperations.insert( ItemModifyJobPrivate::RemoteId ); -} - -ItemModifyJob::~ItemModifyJob() -{ -} - -void ItemModifyJob::doStart() -{ - Q_D( ItemModifyJob ); - - QList changes; - foreach ( int op, d->mOperations ) { - switch ( op ) { - case ItemModifyJobPrivate::RemoteId: - if ( !d->mItem.remoteId().isNull() ) { - changes << "REMOTEID.SILENT"; - changes << ImapParser::quote( d->mItem.remoteId().toLatin1() ); - } - break; - case ItemModifyJobPrivate::Dirty: - changes << "DIRTY.SILENT"; - changes << "false"; - break; - } - } - - if ( d->mItem.d_func()->mFlagsOverwritten ) { - changes << "FLAGS.SILENT"; - changes << '(' + ImapParser::join( d->mItem.flags(), " " ) + ')'; - } else { - if ( !d->mItem.d_func()->mAddedFlags.isEmpty() ) { - changes << "+FLAGS.SILENT"; - changes << '(' + ImapParser::join( d->mItem.d_func()->mAddedFlags, " " ) + ')'; - } - if ( !d->mItem.d_func()->mDeletedFlags.isEmpty() ) { - changes << "-FLAGS.SILENT"; - changes << '(' + ImapParser::join( d->mItem.d_func()->mDeletedFlags, " " ) + ')'; - } - } - - if ( !d->mItem.d_func()->mDeletedAttributes.isEmpty() ) { - changes << "-PARTS.SILENT"; - QList attrs; - foreach ( const QByteArray &attr, d->mItem.d_func()->mDeletedAttributes ) - attrs << ProtocolHelper::encodePartIdentifier( ProtocolHelper::PartAttribute, attr ); - changes << '(' + ImapParser::join( attrs, " " ) + ')'; - } - - // nothing to do - if ( changes.isEmpty() && d->mParts.isEmpty() ) { - emitResult(); - return; - } - - d->mTag = d->newTag(); - QByteArray command = d->mTag; - command += " UID STORE " + QByteArray::number( d->mItem.id() ) + ' '; - if ( !d->mRevCheck ) { - command += "NOREV "; - } else { - command += "REV " + QByteArray::number( d->mItem.revision() ); - } - - command += " (" + ImapParser::join( changes, " " ); - const QByteArray attrs = ProtocolHelper::attributesToByteArray( d->mItem, true ); - if ( !attrs.isEmpty() ) - command += ' ' + attrs; - command += d->nextPartHeader(); - d->writeData( command ); - d->newTag(); // hack to circumvent automatic response handling -} - -void ItemModifyJob::doHandleResponse(const QByteArray &_tag, const QByteArray & data) -{ - Q_D( ItemModifyJob ); - - if ( _tag == "+" ) { // ready for literal data - d->writeData( d->mPendingData ); - d->writeData( d->nextPartHeader() ); - return; - } - if ( _tag == d->mTag ) { - if ( data.startsWith( "OK" ) ) { - // increase item revision of own copy of item - d->mItem.setRevision( d->mItem.revision() + 1 ); - d->mItem.d_ptr->resetChangeLog(); - } else { - setError( Unknown ); - setErrorText( QString::fromUtf8( data ) ); - } - emitResult(); - return; - } - kDebug( 5250 ) << "Unhandled response: " << _tag << data; -} - -void ItemModifyJob::setIgnorePayload( bool ignore ) -{ - Q_D( ItemModifyJob ); - - if ( d->mIgnorePayload == ignore ) - return; - - d->mIgnorePayload = ignore; - if ( d->mIgnorePayload ) - d->mParts = QSet(); - else { - Q_ASSERT( !d->mItem.mimeType().isEmpty() ); - d->mParts = d->mItem.loadedPayloadParts(); - } -} - -bool ItemModifyJob::ignorePayload() const -{ - Q_D( const ItemModifyJob ); - - return d->mIgnorePayload; -} - -void ItemModifyJob::disableRevisionCheck() -{ - Q_D( ItemModifyJob ); - - d->mRevCheck = false; -} - -Item ItemModifyJob::item() const -{ - Q_D( const ItemModifyJob ); - - return d->mItem; -} - -#include "itemmodifyjob.moc" diff --git a/akonadi/itemmodifyjob.h b/akonadi/itemmodifyjob.h deleted file mode 100644 index c0776f392..000000000 --- a/akonadi/itemmodifyjob.h +++ /dev/null @@ -1,123 +0,0 @@ -/* - Copyright (c) 2006 - 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_ITEMMODIFYJOB_H -#define AKONADI_ITEMMODIFYJOB_H - -#include "akonadi_export.h" - -#include -#include - -namespace Akonadi { - -class Collection; -class ItemModifyJobPrivate; - -/** - * @short Job that modifies an existing item in the Akonadi storage. - * - * This job is used to writing back items to the Akonadi storage, after - * the user has changed them in any way. - * For performance reasons either the full item (including the full payload) - * can written back or only the meta data of the item. - * - * Example: - * - * @code - * - * // Fetch item with unique id 125 - * Akonadi::ItemFetchJob *fetchJob = new Akonadi::ItemFetchJob( Akonadi::Item( 125 ) ); - * if ( fetchJob->exec() ) { - * Akonadi::Item item = fetchJob->items().first(); - * - * // Set a custom flag - * item.setFlag( "\GotIt" ); - * - * // Store back modified item - * Akonadi::ItemModifyJob *modifyJob = new Akonadi::ItemModifyJob( item ); - * if ( modifyJob->exec() ) - * qDebug() << "Item modified successfully"; - * else - * qDebug() << "Error occurred"; - * } else { - * qDebug() << "Error occurred"; - * } - * - * @endcode - * - * @author Volker Krause - */ -class AKONADI_EXPORT ItemModifyJob : public Job -{ - friend class ResourceBase; - - Q_OBJECT - - public: - /** - * Creates a new item modify job. - * - * @param item The modified item object to store. - * @param parent The parent object. - */ - explicit ItemModifyJob( const Item &item, QObject *parent = 0 ); - - /** - * Destroys the item modify job. - */ - virtual ~ItemModifyJob(); - - /** - * Sets whether the payload of the modified item shall be - * omitted from transmission to the Akonadi storage. - * The default is @c false, however it can be set for - * performance reasons. - */ - void setIgnorePayload( bool ignore ); - - /** - * Returns whether the payload of the modified item shall be - * omitted from transmission to the Akonadi storage. - */ - bool ignorePayload() const; - - /** - * Disables the check of the revision number. - * - * @note If disabled, no conflict detection is available. - */ - void disableRevisionCheck(); - - /** - * Returns the modified and stored item including the changed revision number. - */ - Item item() const; - - protected: - virtual void doStart(); - virtual void doHandleResponse( const QByteArray &tag, const QByteArray &data ); - - private: - Q_DECLARE_PRIVATE( ItemModifyJob ) -}; - -} - -#endif diff --git a/akonadi/itemmodifyjob_p.h b/akonadi/itemmodifyjob_p.h deleted file mode 100644 index 38a92c8f6..000000000 --- a/akonadi/itemmodifyjob_p.h +++ /dev/null @@ -1,57 +0,0 @@ -/* - Copyright (c) 2006 - 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_ITEMMODIFYJOB_P_H -#define AKONADI_ITEMMODIFYJOB_P_H - -#include "job_p.h" - -namespace Akonadi { - -/** - * @internal - */ -class ItemModifyJobPrivate : public JobPrivate -{ - public: - enum Operation - { - RemoteId, - Dirty - }; - - ItemModifyJobPrivate( ItemModifyJob *parent, const Item &item ); - - void setClean(); - QByteArray nextPartHeader(); - - Q_DECLARE_PUBLIC( ItemModifyJob ) - - QSet mOperations; - QByteArray mTag; - Item mItem; - bool mRevCheck; - QSet mParts; - QByteArray mPendingData; - bool mIgnorePayload; -}; - -} - -#endif diff --git a/akonadi/itemmonitor.cpp b/akonadi/itemmonitor.cpp deleted file mode 100644 index acf11b6de..000000000 --- a/akonadi/itemmonitor.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/* - Copyright (c) 2007-2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "itemmonitor.h" -#include "itemmonitor_p.h" - -#include "itemfetchscope.h" - -#include - -using namespace Akonadi; - -ItemMonitor::ItemMonitor() - : d( new Private( this ) ) -{ -} - -ItemMonitor::~ItemMonitor() -{ - delete d; -} - -void ItemMonitor::setItem( const Item &item ) -{ - if ( item == d->mItem ) - return; - - d->mMonitor->setItemMonitored( d->mItem, false ); - - d->mItem = item; - - d->mMonitor->setItemMonitored( d->mItem, true ); - - // start initial fetch of the new item - ItemFetchJob* job = new ItemFetchJob( d->mItem ); - job->setFetchScope( fetchScope() ); - - d->connect( job, SIGNAL( result( KJob* ) ), d, SLOT( initialFetchDone( KJob* ) ) ); -} - -Item ItemMonitor::item() const -{ - return d->mItem; -} - -void ItemMonitor::itemChanged( const Item& ) -{ -} - -void ItemMonitor::itemRemoved() -{ -} - -void ItemMonitor::setFetchScope( const ItemFetchScope &fetchScope ) -{ - d->mMonitor->setItemFetchScope( fetchScope ); -} - -ItemFetchScope &ItemMonitor::fetchScope() -{ - return d->mMonitor->itemFetchScope(); -} - -#include "itemmonitor_p.moc" diff --git a/akonadi/itemmonitor.h b/akonadi/itemmonitor.h deleted file mode 100644 index 2fb14f18f..000000000 --- a/akonadi/itemmonitor.h +++ /dev/null @@ -1,154 +0,0 @@ -/* - Copyright (c) 2007-2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_ITEMMONITOR_H -#define AKONADI_ITEMMONITOR_H - -#include "akonadi_export.h" - -class QStringList; - -namespace Akonadi { - -class Item; -class ItemFetchScope; - -/** - * @short A convenience class to monitor a single item for changes. - * - * This class can be used as a base class for classes that want to show - * a single item to the user and keep track of status changes of the item - * without having to using a Monitor object themself. - * - * Example: - * - * @code - * - * // A label that shows the name of a contact item - * - * class ContactLabel : public QLabel, public Akonadi::ItemMonitor - * { - * public: - * ContactLabel( QWidget *parent = 0 ) - * : QLabel( parent ) - * { - * setText( "No Name" ); - * } - * - * protected: - * virtual void itemChanged( const Akonadi::Item &item ) - * { - * if ( item.mimeType() != "text/directory" ) - * return; - * - * const KABC::Addressee addr = item.payload(); - * setText( addr.fullName() ); - * } - * - * virtual void itemRemoved() - * { - * setText( "No Name" ); - * } - * }; - * - * ... - * - * ContactLabel *label = new ContactLabel( this ); - * - * const Akonadi::Item item = fetchJob->items().first(); - * label->setItem( item ); - * - * @endcode - * - * @author Tobias Koenig - */ -class AKONADI_EXPORT ItemMonitor -{ - public: - /** - * Creates a new item monitor. - */ - ItemMonitor(); - - /** - * Destroys the item monitor. - */ - virtual ~ItemMonitor(); - - /** - * Sets the @p item that shall be monitored. - */ - void setItem( const Item &item ); - - /** - * Returns the currently monitored item. - */ - Item item() const; - - protected: - /** - * This method is called whenever the monitored item has changed. - * - * @param item The changed item. - */ - virtual void itemChanged( const Item &item ); - - /** - * This method is called whenever the monitored item has been removed. - */ - virtual void itemRemoved(); - - /** - * Sets the item fetch scope. - * - * Controls how much of an item's data is fetched from the server, e.g. - * whether to fetch the full item payload or only meta data. - * - * @param fetchScope The new scope for item fetch operations. - * - * @see fetchScope() - */ - void setFetchScope( const ItemFetchScope &fetchScope ); - - /** - * Returns the item fetch scope. - * - * Since this returns a reference it can be used to conveniently modify the - * current scope in-place, i.e. by calling a method on the returned reference - * without storing it in a local variable. See the ItemFetchScope documentation - * for an example. - * - * @return a reference to the current item fetch scope - * - * @see setFetchScope() for replacing the current item fetch scope - */ - ItemFetchScope &fetchScope(); - - private: - //@cond PRIVATE - class Private; - Private* const d; - //@endcond - - Q_DISABLE_COPY( ItemMonitor ) -}; - -} - -#endif diff --git a/akonadi/itemmonitor_p.h b/akonadi/itemmonitor_p.h deleted file mode 100644 index c815ec079..000000000 --- a/akonadi/itemmonitor_p.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - Copyright (c) 2007-2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_ITEMMONITOR_P_H -#define AKONADI_ITEMMONITOR_P_H - -#include - -#include -#include - -namespace Akonadi { - -/** - * @internal - */ -class ItemMonitor::Private : public QObject -{ - Q_OBJECT - - public: - Private( ItemMonitor *parent ) - : QObject( 0 ), - mParent( parent ), mMonitor( new Monitor() ) - { - connect( mMonitor, SIGNAL( itemChanged( const Akonadi::Item&, const QSet& ) ), - SLOT( slotItemChanged( const Akonadi::Item&, const QSet& ) ) ); - connect( mMonitor, SIGNAL( itemRemoved( const Akonadi::Item& ) ), - SLOT( slotItemRemoved( const Akonadi::Item& ) ) ); - } - - ~Private() - { - delete mMonitor; - } - - ItemMonitor *mParent; - Item mItem; - Monitor *mMonitor; - - private Q_SLOTS: - void slotItemChanged( const Akonadi::Item &item, const QSet& ) - { - mParent->itemChanged( item ); - } - - void slotItemRemoved( const Akonadi::Item& ) - { - mParent->itemRemoved(); - } - - void initialFetchDone( KJob *job ) - { - if ( job->error() ) - return; - - ItemFetchJob *fetchJob = qobject_cast( job ); - - if ( !fetchJob->items().isEmpty() ) - mParent->itemChanged( fetchJob->items().first() ); - } -}; - -} - -#endif diff --git a/akonadi/itemmovejob.cpp b/akonadi/itemmovejob.cpp deleted file mode 100644 index b18a5d389..000000000 --- a/akonadi/itemmovejob.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "itemmovejob.h" - -#include "collection.h" -#include "item.h" -#include "job_p.h" - -using namespace Akonadi; - -class Akonadi::ItemMoveJobPrivate: public JobPrivate -{ - public: - ItemMoveJobPrivate( ItemMoveJob *parent ) - : JobPrivate( parent ) - { - } - - Collection mTarget; - Item mItem; -}; - -ItemMoveJob::ItemMoveJob(const Item & item, const Collection & target, QObject * parent) : - Job( new ItemMoveJobPrivate( this ), parent ) -{ - Q_D( ItemMoveJob ); - d->mTarget = target; - d->mItem = item; -} - -ItemMoveJob::~ ItemMoveJob() -{ -} - -void ItemMoveJob::doStart() -{ - Q_D( ItemMoveJob ); - - QByteArray command = d->newTag(); - command += " UID STORE " + QByteArray::number( d->mItem.id() ); - command += " NOREV (COLLECTION.SILENT " + QByteArray::number( d->mTarget.id() ) + ")\n"; - d->writeData( command ); -} - -#include "itemmovejob.moc" diff --git a/akonadi/itemmovejob.h b/akonadi/itemmovejob.h deleted file mode 100644 index f2930c1af..000000000 --- a/akonadi/itemmovejob.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_ITEMMOVEJOB_H -#define AKONADI_ITEMMOVEJOB_H - -#include - - -namespace Akonadi { - -class Collection; -class Item; -class ItemMoveJobPrivate; - -/** - * @short Job that moves an item into a different collection in the Akonadi storage. - * - * This job takes an item and moves it to a collection in the Akonadi storage. - * - * @code - * - * Akonadi::Item item = ... - * Akonadi::Collection collection = Akonadi::Collection::root(); - * - * Akonadi::ItemMoveJob *job = new Akonadi::ItemMoveJob( item, collection ); - * if ( job->exec() ) - * qDebug() << "Item moved successfully"; - * else - * qDebug() << "Error occurred"; - * - * @endcode - * - * @author Volker Krause - */ -class AKONADI_EXPORT ItemMoveJob : public Job -{ - Q_OBJECT - - public: - /** - * Move the given item into the given collection. - * - * @param item The item to move. - * @param target The target collection. - * @param parent The parent object. - */ - ItemMoveJob( const Item &item, const Collection &target, QObject *parent = 0 ); - - /** - * Destroys the item move job. - */ - ~ItemMoveJob(); - - protected: - void doStart(); - - private: - Q_DECLARE_PRIVATE( ItemMoveJob ) -}; - -} - -#endif diff --git a/akonadi/itempayloadinternals_p.h b/akonadi/itempayloadinternals_p.h deleted file mode 100644 index dacfad2c3..000000000 --- a/akonadi/itempayloadinternals_p.h +++ /dev/null @@ -1,84 +0,0 @@ -/* - Copyright (c) 2007 Till Adam - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef ITEMPAYLOADINTERNALS_P_H -#define ITEMPAYLOADINTERNALS_P_H - -#include - -#include - -/* WARNING - * The below is an implementation detail of the Item class. It is not to be - * considered public API, and subject to change without notice - */ - -/** - * @internal - */ -struct PayloadBase -{ - virtual ~PayloadBase() { } - virtual PayloadBase * clone() const = 0; - virtual const char* typeName() const = 0; -}; - -/** - * @internal - */ -template -struct Payload : public PayloadBase -{ - Payload( T p ) { payload = p; } - Payload( const Payload& other ) - { - payload = other.payload; - } - Payload & operator=( const Payload & other ) - { - payload = other.payload; - } - - PayloadBase * clone() const - { - return new Payload( const_cast* >(this)->payload); - } - - const char* typeName() const - { - return typeid(const_cast*> (this)).name(); - } - - T payload; -}; - -/** - * @internal - */ -template -struct Payload : public PayloadBase -{ - Payload( T* ) - { - Q_ASSERT_X( false, "Akonadi::Payload", "The Item class is not intended to be used with raw pointer types. Please use a smart pointer instead." ); - } -}; - -#endif - diff --git a/akonadi/itemserializer.cpp b/akonadi/itemserializer.cpp deleted file mode 100644 index 29b2a154c..000000000 --- a/akonadi/itemserializer.cpp +++ /dev/null @@ -1,215 +0,0 @@ -/* - Copyright (c) 2007 Till Adam - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "itemserializer.h" -#include "item.h" -#include "itemserializerplugin.h" -#include "attributefactory.h" - -// KDE core -#include -#include -#include - -// Qt -#include -#include -#include -#include -#include - -// temporary -#include "pluginloader.h" - - - -namespace Akonadi { - -class DefaultItemSerializerPlugin; - -class DefaultItemSerializerPlugin : public ItemSerializerPlugin -{ -public: - DefaultItemSerializerPlugin() { } - - bool deserialize( Item& item, const QByteArray& label, QIODevice& data, int ) - { - if ( label != Item::FullPayload ) - return false; - item.setPayload( data.readAll() ); - return true; - } - - void serialize( const Item& item, const QByteArray& label, QIODevice& data, int& ) - { - Q_ASSERT( label == Item::FullPayload ); - if ( item.hasPayload() ) - data.write( item.payload() ); - } - -}; - -K_GLOBAL_STATIC( DefaultItemSerializerPlugin, s_defaultItemSerializerPlugin ) - -} - - -using namespace Akonadi; - -class PluginEntry -{ - public: - PluginEntry() - : mPlugin( 0 ) - { - } - - PluginEntry( const QString &identifier ) - : mIdentifier( identifier ), mPlugin( 0 ) - { - } - - inline ItemSerializerPlugin* plugin() const - { - if ( mPlugin ) - return mPlugin; - - QObject *object = PluginLoader::self()->createForName( mIdentifier ); - if ( !object ) { - kWarning( 5250 ) << "ItemSerializerPluginLoader: " - << "plugin" << mIdentifier << "is not valid!" << endl; - - // we try to use the default in that case - mPlugin = s_defaultItemSerializerPlugin; - } - - mPlugin = qobject_cast( object ); - if ( !mPlugin ) { - kWarning( 5250 ) << "ItemSerializerPluginLoader: " - << "plugin" << mIdentifier << "doesn't provide interface ItemSerializerPlugin!" << endl; - - // we try to use the default in that case - mPlugin = s_defaultItemSerializerPlugin; - } - - Q_ASSERT( mPlugin ); - - return mPlugin; - } - - private: - QString mIdentifier; - mutable ItemSerializerPlugin *mPlugin; -}; - -static QHash * all = 0; - -static void loadPlugins() { - const PluginLoader* pl = PluginLoader::self(); - if ( !pl ) { - kWarning( 5250 ) << "Cannot instantiate plugin loader!" << endl; - return; - } - const QStringList types = pl->types(); - kDebug( 5250 ) << "ItemSerializerPluginLoader: " - << "found" << types.size() << "plugins." << endl; - for ( QStringList::const_iterator it = types.begin() ; it != types.end() ; ++it ) { - all->insert( *it, PluginEntry( *it ) ); - } -} - -static void setup() -{ - if (!all) { - all = new QHash(); - loadPlugins(); - } -} - -/*static*/ -void ItemSerializer::deserialize( Item& item, const QByteArray& label, const QByteArray& data, int version ) -{ - QBuffer buffer; - buffer.setData( data ); - buffer.open( QIODevice::ReadOnly ); - buffer.seek( 0 ); - deserialize( item, label, buffer, version ); - buffer.close(); -} - -/*static*/ -void ItemSerializer::deserialize( Item& item, const QByteArray& label, QIODevice& data, int version ) -{ - setup(); - if ( !ItemSerializer::pluginForMimeType( item.mimeType() ).deserialize( item, label, data, version ) ) - kWarning() << "Unable to deserialize payload part:" << label; -} - -/*static*/ -void ItemSerializer::serialize( const Item& item, const QByteArray& label, QByteArray& data, int &version ) -{ - QBuffer buffer; - buffer.setBuffer( &data ); - buffer.open( QIODevice::WriteOnly ); - buffer.seek( 0 ); - serialize( item, label, buffer, version ); - buffer.close(); -} - -/*static*/ -void ItemSerializer::serialize( const Item& item, const QByteArray& label, QIODevice& data, int &version ) -{ - if ( !item.hasPayload() ) - return; - setup(); - ItemSerializerPlugin& plugin = pluginForMimeType( item.mimeType() ); - plugin.serialize( item, label, data, version ); -} - -QSet ItemSerializer::parts(const Item & item) -{ - if ( !item.hasPayload() ) - return QSet(); - setup(); - return pluginForMimeType( item.mimeType() ).parts( item ); -} - -/*static*/ -ItemSerializerPlugin& ItemSerializer::pluginForMimeType( const QString & mimetype ) -{ - if ( all->contains( mimetype ) ) - return *(all->value( mimetype ).plugin()); - - KMimeType::Ptr mimeType = KMimeType::mimeType( mimetype, KMimeType::ResolveAliases ); - if ( !mimeType.isNull() ) { - foreach ( const QString &type, all->keys() ) { - if ( mimeType->is( type ) ) { - return *(all->value( type ).plugin() ); - } - } - } - - kDebug( 5250 ) << "No plugin for mimetype " << mimetype << " found!"; - kDebug( 5250 ) << "Available plugins are: " << all->keys(); - - ItemSerializerPlugin *plugin = s_defaultItemSerializerPlugin; - Q_ASSERT(plugin); - return *plugin; -} diff --git a/akonadi/itemserializer.h b/akonadi/itemserializer.h deleted file mode 100644 index 8c4aeeed0..000000000 --- a/akonadi/itemserializer.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - Copyright (c) 2007 Till Adam - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_ITEM_SERIALIZER_H -#define AKONADI_ITEM_SERIALIZER_H - -#include -#include - -#include "akonadiprivate_export.h" - -class QIODevice; - -namespace Akonadi { - -class Item; -class ItemSerializerPlugin; - -/** - @internal - Serialization/Deserialization of item parts, serializer plugin management. -*/ -class AKONADI_TESTS_EXPORT ItemSerializer -{ - public: - /** throws ItemSerializerException on failure */ - static void deserialize( Item& item, const QByteArray& label, const QByteArray& data, int version ); - /** throws ItemSerializerException on failure */ - static void deserialize( Item& item, const QByteArray& label, QIODevice& data, int version ); - /** throws ItemSerializerException on failure */ - static void serialize( const Item& item, const QByteArray& label, QByteArray& data, int &version ); - /** throws ItemSerializerException on failure */ - static void serialize( const Item& item, const QByteArray& label, QIODevice& data, int &version ); - - /** Returns a list of parts available in the item payload. */ - static QSet parts( const Item &item ); - - private: - static ItemSerializerPlugin& pluginForMimeType( const QString& mimetype ); -}; - -} - -#endif diff --git a/akonadi/itemserializerplugin.cpp b/akonadi/itemserializerplugin.cpp deleted file mode 100644 index 0631d7c10..000000000 --- a/akonadi/itemserializerplugin.cpp +++ /dev/null @@ -1,36 +0,0 @@ -/* - Copyright (c) 2007 Till Adam - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "itemserializerplugin.h" -#include "item.h" - -using namespace Akonadi; - -ItemSerializerPlugin::~ItemSerializerPlugin() -{ -} - -QSet ItemSerializerPlugin::parts(const Item & item) const -{ - QSet set; - if ( item.hasPayload() ) - set.insert( Item::FullPayload ); - return set; -} diff --git a/akonadi/itemserializerplugin.h b/akonadi/itemserializerplugin.h deleted file mode 100644 index aae3801b0..000000000 --- a/akonadi/itemserializerplugin.h +++ /dev/null @@ -1,181 +0,0 @@ -/* - Copyright (c) 2007 Till Adam - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_ITEMSERIALIZERPLUGIN_H -#define AKONADI_ITEMSERIALIZERPLUGIN_H - -#include -#include - -#include "akonadi_export.h" - -class QIODevice; - -namespace Akonadi { - -class Item; - -/** - * @short The base class for item type serializer plugins. - * - * Serializer plugins convert between the payload of Akonadi::Item objects and - * a textual or binary representation of the actual content data. - * This allows to easily add support for new types to Akonadi. - * - * The following example shows how to implement a serializer plugin for - * a new data type PimNote. - * - * The PimNote data structure: - * @code - * typedef struct { - * QString author; - * QDateTime dateTime; - * QString text; - * } PimNote; - * @endcode - * - * The serializer plugin code: - * @code - * #include - * - * class SerializerPluginPimNote : public QObject, public Akonadi::ItemSerializerPlugin - * { - * Q_OBJECT - * Q_INTERFACES( Akonadi::ItemSerializerPlugin ) - * - * public: - * bool deserialize( Akonadi::Item& item, const QByteArray& label, QIODevice& data, int version ) - * { - * // we don't handle versions in this example - * Q_UNUSED( version ); - * - * // we work only on full payload - * if ( label != Akonadi::Item::FullPayload ) - * return false; - * - * QDataStream stream( &data ); - * - * PimNote note; - * stream >> note.author; - * stream >> note.dateTime; - * stream >> note.text; - * - * item.setPayload( note ); - * - * return true; - * } - * - * void serialize( const Akonadi::Item& item, const QByteArray& label, QIODevice& data, int &version ) - * { - * // we don't handle versions in this example - * Q_UNUSED( version ); - * - * if ( label != Akonadi::Item::FullPayload || !item.hasPayload() ) - * return; - * - * QDataStream stream( &data ); - * - * PimNote note = item.payload(); - * - * stream << note.author; - * stream << note.dateTime; - * stream << note.text; - * } - * }; - * - * Q_EXPORT_PLUGIN2( akonadi_serializer_pimnote, SerializerPluginPimNote ) - * - * @endcode - * - * The desktop file: - * @code - * [Misc] - * Name=Pim Note Serializer - * Comment=An Akonadi serializer plugin for note objects - * - * [Plugin] - * Type=application/x-pimnote - * X-KDE-Library=akonadi_serializer_pimnote - * @endcode - * - * @author Till Adam , Volker Krause - */ -class AKONADI_EXPORT ItemSerializerPlugin -{ -public: - /** - * Destroys the item serializer plugin. - */ - virtual ~ItemSerializerPlugin(); - - /** - * Converts serialized item data provided in @p data into payload for @p item. - * - * @param item The item to which the payload should be added. - * It is guaranteed to have a mime type matching one of the supported - * mime types of this plugin. - * However it might contain a unsuited payload added manually - * by the application developer. - * Verifying the payload type in case a payload is already available - * is recommended therefore. - * @param label The part identifier of the part to deserialize. - * @p label might be an unsupported item part, return @c false if this is the case. - * @param data A QIODevice providing access to the serialized data. - * The QIODevice is opened in read-only mode and positioned at the beginning. - * The QIODevice is guaranteed to be valid. - * @param version The version of the data format as set by the user in serialize() or @c 0 (default). - * @return @c false if the specified part is not supported by this plugin, @c true if the part - * could be de-serialized successfully. - */ - virtual bool deserialize( Item& item, const QByteArray& label, QIODevice& data, int version ) = 0; - - /** - * Convert the payload object provided in @p item into its serialzed form into @p data. - * - * @param item The item which contains the payload. - * It is guaranteed to have a mimetype matching one of the supported - * mimetypes of this plugin as well as the existence of a payload object. - * However it might contain an unsupported payload added manually by - * the application developer. - * Verifying the payload type is recommended therefore. - * @param label The part identifier of the part to serialize. - * @p label will be one of the item parts returned by parts(). - * @param data The QIODevice where the serialized data should be written to. - * The QIODevice is opened in write-only mode and positioned at the beginning. - * The QIODevice is guaranteed to be valid. - * @param version The version of the data format. Can be set by the user to handle different - * versions. - */ - virtual void serialize( const Item& item, const QByteArray& label, QIODevice& data, int &version ) = 0; - - /** - * Returns a list of available parts for the given item payload. - * The default implementation returns Item::FullPayload if a payload is set. - * - * @param item The item. - */ - virtual QSet parts( const Item &item ) const; -}; - -} - -Q_DECLARE_INTERFACE( Akonadi::ItemSerializerPlugin, "org.freedesktop.Akonadi.ItemSerializerPlugin/1.0" ) - -#endif diff --git a/akonadi/itemsync.cpp b/akonadi/itemsync.cpp deleted file mode 100644 index 1424e9f13..000000000 --- a/akonadi/itemsync.cpp +++ /dev/null @@ -1,382 +0,0 @@ -/* - Copyright (c) 2007 Tobias Koenig - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "itemsync.h" - -#include "collection.h" -#include "item.h" -#include "itemcreatejob.h" -#include "itemdeletejob.h" -#include "itemfetchjob.h" -#include "itemmodifyjob.h" -#include "transactionsequence.h" -#include "itemfetchscope.h" - -#include - -#include - -using namespace Akonadi; - -/** - * @internal - */ -class ItemSync::Private -{ - public: - Private( ItemSync *parent ) : - q( parent ), - mTransactionMode( Single ), - mCurrentTransaction( 0 ), - mTransactionJobs( 0 ), - mPendingJobs( 0 ), - mProgress( 0 ), - mTotalItems( -1 ), - mTotalItemsProcessed( 0 ), - mStreaming( false ), - mIncremental( false ), - mLocalListDone( false ), - mDeliveryDone( false ) - { - // we want to fetch all data by default - mFetchScope.fetchFullPayload(); - mFetchScope.fetchAllAttributes(); - } - - void createLocalItem( const Item &item ); - void checkDone(); - void slotLocalListDone( KJob* ); - void slotLocalChangeDone( KJob* ); - void execute(); - void processItems(); - void deleteItems( const Item::List &items ); - void slotTransactionResult( KJob *job ); - Job* subjobParent() const; - - ItemSync *q; - Collection mSyncCollection; - QHash mLocalItemsById; - QHash mLocalItemsByRemoteId; - QSet mUnprocessedLocalItems; - - // transaction mode, TODO: make this public API? - enum TransactionMode { - Single, - Chunkwise, - None - }; - TransactionMode mTransactionMode; - TransactionSequence *mCurrentTransaction; - int mTransactionJobs; - - // fetch scope for initial item listing - ItemFetchScope mFetchScope; - - // remote items - Akonadi::Item::List mRemoteItems; - - // removed remote items - Item::List mRemovedRemoteItems; - - // create counter - int mPendingJobs; - int mProgress; - int mTotalItems; - int mTotalItemsProcessed; - - bool mStreaming; - bool mIncremental; - bool mLocalListDone; - bool mDeliveryDone; -}; - -void ItemSync::Private::createLocalItem( const Item & item ) -{ - mPendingJobs++; - ItemCreateJob *create = new ItemCreateJob( item, mSyncCollection, subjobParent() ); - q->connect( create, SIGNAL( result( KJob* ) ), q, SLOT( slotLocalChangeDone( KJob* ) ) ); -} - -void ItemSync::Private::checkDone() -{ - q->setProcessedAmount( KJob::Bytes, mProgress ); - if ( mPendingJobs > 0 || !mDeliveryDone || mTransactionJobs > 0 ) - return; - - q->emitResult(); -} - -ItemSync::ItemSync( const Collection &collection, QObject *parent ) : - Job( parent ), - d( new Private( this ) ) -{ - d->mSyncCollection = collection; -} - -ItemSync::~ItemSync() -{ - delete d; -} - -void ItemSync::setFullSyncItems( const Item::List &items ) -{ - Q_ASSERT( !d->mIncremental ); - if ( !d->mStreaming ) - d->mDeliveryDone = true; - d->mRemoteItems += items; - d->mTotalItemsProcessed += items.count(); - kDebug() << "Received: " << items.count() << "In total: " << d->mTotalItemsProcessed << " Wanted: " << d->mTotalItems; - setTotalAmount( KJob::Bytes, d->mTotalItemsProcessed ); - if ( d->mTotalItemsProcessed == d->mTotalItems ) - d->mDeliveryDone = true; - d->execute(); -} - -void ItemSync::setTotalItems( int amount ) -{ - Q_ASSERT( !d->mIncremental ); - Q_ASSERT( amount >= 0 ); - setStreamingEnabled( true ); - kDebug() << amount; - d->mTotalItems = amount; - setTotalAmount( KJob::Bytes, amount ); - if ( d->mTotalItems == 0 ) { - d->mDeliveryDone = true; - d->execute(); - } -} - -void ItemSync::setIncrementalSyncItems( const Item::List &changedItems, const Item::List &removedItems ) -{ - d->mIncremental = true; - if ( !d->mStreaming ) - d->mDeliveryDone = true; - d->mRemoteItems += changedItems; - d->mRemovedRemoteItems += removedItems; - d->mTotalItemsProcessed += changedItems.count() + removedItems.count(); - setTotalAmount( KJob::Bytes, d->mTotalItemsProcessed ); - if ( d->mTotalItemsProcessed == d->mTotalItems ) - d->mDeliveryDone = true; - d->execute(); -} - -void ItemSync::setFetchScope( ItemFetchScope &fetchScope ) -{ - d->mFetchScope = fetchScope; -} - -ItemFetchScope &ItemSync::fetchScope() -{ - return d->mFetchScope; -} - -void ItemSync::doStart() -{ - ItemFetchJob* job = new ItemFetchJob( d->mSyncCollection, this ); - job->setFetchScope( d->mFetchScope ); - - // we only can fetch parts already in the cache, otherwise this will deadlock - job->fetchScope().setCacheOnly( true ); - - connect( job, SIGNAL( result( KJob* ) ), SLOT( slotLocalListDone( KJob* ) ) ); -} - -bool ItemSync::updateItem( const Item &storedItem, Item &newItem ) -{ - /* - * We know that this item has changed (as it is part of the - * incremental changed list), so we just put it into the - * storage. - */ - if ( d->mIncremental ) - return true; - - // Check whether the flags differ - if ( storedItem.flags() != newItem.flags() ) { - kDebug( 5250 ) << "Stored flags " << storedItem.flags() - << "new flags " << newItem.flags(); - return true; - } - - // Check whether the new item contains unknown parts - QSet missingParts = storedItem.loadedPayloadParts(); - missingParts.subtract( newItem.loadedPayloadParts() ); - if ( !missingParts.isEmpty() ) - return true; - - // ### FIXME SLOW!!! - // If the available part identifiers don't differ, check - // whether the content of the payload differs - if ( storedItem.payloadData() != newItem.payloadData() ) - return true; - - // check if remote attributes have been changed - foreach ( Attribute* attr, newItem.attributes() ) { - if ( !storedItem.hasAttribute( attr->type() ) ) - return true; - if ( attr->serialized() != storedItem.attribute( attr->type() )->serialized() ) - return true; - } - - return false; -} - -void ItemSync::Private::slotLocalListDone( KJob * job ) -{ - if ( job->error() ) - return; - - const Item::List list = static_cast( job )->items(); - foreach ( const Item &item, list ) { - mLocalItemsById.insert( item.id(), item ); - mLocalItemsByRemoteId.insert( item.remoteId(), item ); - mUnprocessedLocalItems.insert( item ); - } - - mLocalListDone = true; - execute(); -} - -void ItemSync::Private::execute() -{ - if ( !mLocalListDone ) - return; - - if ( (mTransactionMode == Single && !mCurrentTransaction) || mTransactionMode == Chunkwise ) { - ++mTransactionJobs; - mCurrentTransaction = new TransactionSequence( q ); - connect( mCurrentTransaction, SIGNAL(result(KJob*)), q, SLOT(slotTransactionResult(KJob*)) ); - } - - processItems(); - if ( !mDeliveryDone ) { - if ( mTransactionMode == Chunkwise && mCurrentTransaction ) { - mCurrentTransaction->commit(); - mCurrentTransaction = 0; - } - return; - } - - // removed - if ( !mIncremental ) { - mRemovedRemoteItems = mUnprocessedLocalItems.toList(); - mUnprocessedLocalItems.clear(); - } - - deleteItems( mRemovedRemoteItems ); - mLocalItemsById.clear(); - mLocalItemsByRemoteId.clear(); - mRemovedRemoteItems.clear(); - - if ( mCurrentTransaction ) { - mCurrentTransaction->commit(); - mCurrentTransaction = 0; - } - - checkDone(); -} - -void ItemSync::Private::processItems() -{ - // added / updated - foreach ( Item remoteItem, mRemoteItems ) { -#ifndef NDEBUG - if ( remoteItem.remoteId().isEmpty() ) { - kWarning( 5250 ) << "Item " << remoteItem.id() << " does not have a remote identifier"; - } -#endif - - Item localItem = mLocalItemsById.value( remoteItem.id() ); - if ( !localItem.isValid() ) - localItem = mLocalItemsByRemoteId.value( remoteItem.remoteId() ); - mUnprocessedLocalItems.remove( localItem ); - // missing locally - if ( !localItem.isValid() ) { - createLocalItem( remoteItem ); - continue; - } - - if ( q->updateItem( localItem, remoteItem ) ) { - mPendingJobs++; - - remoteItem.setId( localItem.id() ); - remoteItem.setRevision( localItem.revision() ); - remoteItem.setRemoteId( localItem.remoteId() ); // in case someone clears remoteId by accident - ItemModifyJob *mod = new ItemModifyJob( remoteItem, subjobParent() ); - q->connect( mod, SIGNAL( result( KJob* ) ), q, SLOT( slotLocalChangeDone( KJob* ) ) ); - } else { - mProgress++; - } - } - mRemoteItems.clear(); -} - -void ItemSync::Private::deleteItems( const Item::List &items ) -{ - foreach ( const Item &item, items ) { - mPendingJobs++; - ItemDeleteJob *job = new ItemDeleteJob( item, subjobParent() ); - q->connect( job, SIGNAL( result( KJob* ) ), q, SLOT( slotLocalChangeDone( KJob* ) ) ); - } -} - -void ItemSync::Private::slotLocalChangeDone( KJob * job ) -{ - if ( job->error() ) - return; - - mPendingJobs--; - mProgress++; - - checkDone(); -} - -void ItemSync::Private::slotTransactionResult( KJob *job ) -{ - if ( job->error() ) - return; - - --mTransactionJobs; - if ( mCurrentTransaction == job ) - mCurrentTransaction = 0; - - checkDone(); -} - -Job * ItemSync::Private::subjobParent() const -{ - if ( mCurrentTransaction && mTransactionMode != None ) - return mCurrentTransaction; - return q; -} - -void ItemSync::setStreamingEnabled(bool enable) -{ - d->mStreaming = enable; -} - -void ItemSync::deliveryDone() -{ - Q_ASSERT( d->mStreaming ); - d->mDeliveryDone = true; - d->execute(); -} - -#include "itemsync.moc" diff --git a/akonadi/itemsync.h b/akonadi/itemsync.h deleted file mode 100644 index c20efd27b..000000000 --- a/akonadi/itemsync.h +++ /dev/null @@ -1,170 +0,0 @@ -/* - Copyright (c) 2007 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_ITEMSYNC_H -#define AKONADI_ITEMSYNC_H - -#include "akonadi_export.h" - -#include -#include - -namespace Akonadi { - -class Collection; -class ItemFetchScope; - -/** - * @short Syncs between items known to a client (usually a resource) and the Akonadi storage. - * - * Remote Id must only be set by the resource storing the item, other clients - * should leave it empty, since the resource responsible for the target collection - * will be notified about the addition and then create a suitable remote Id. - * - * There are two different forms of ItemSync usage: - * - Full-Sync: meaning the client provides all valid items, i.e. any item not - * part of the list but currently stored in Akonadi will be removed - * - Incremental-Sync: meaning the client provides two lists, one for items which - * are new or modified and one for items which should be removed. Any item not - * part of either list but currently stored in Akonadi will not be changed. - * - * @note This is provided for convenience to implement "save all" like behavior, - * however it is strongly recommended to use single item jobs whenever - * possible, e.g. ItemCreateJob, ItemModifyJob and ItemDeleteJob - * - * @author Tobias Koenig - */ -class AKONADI_EXPORT ItemSync : public Job -{ - Q_OBJECT - - public: - /** - * Creates a new item synchronizer. - * - * @param collection The collection we are syncing. - * @param parent The parent object. - */ - explicit ItemSync( const Collection &collection, QObject *parent = 0 ); - - /** - * Destroys the item synchronizer. - */ - ~ItemSync(); - - /** - * Sets the full item list for the collection. - * - * Usually the result of a full item listing. - * - * @warning If the client using this is a resource, all items must have - * a valid remote identifier. - * - * @param items A list of items. - */ - void setFullSyncItems( const Item::List &items ); - - /** - * Set the amount of items which you are going to return in total - * by using the setFullSyncItems() method. - * - * @param amount The amount of items in total. - */ - void setTotalItems( int amount ); - - /** - Enable item streaming. Item streaming means that the items delivered by setXItems() calls - are delivered in chunks and you manually indicate when all items have been delivered - by calling deliveryDone(). - @param enable @c true to enable item streaming - */ - void setStreamingEnabled( bool enable ); - - /** - Notify ItemSync that all remote items have been delivered. - Only call this in streaming mode. - */ - void deliveryDone(); - - /** - * Sets the item lists for incrementally syncing the collection. - * - * Usually the result of an incremental remote item listing. - * - * @warning If the client using this is a resource, all items must have - * a valid remote identifier. - * - * @param changedItems A list of items added or changed by the client. - * @param removedItems A list of items deleted by the client. - */ - void setIncrementalSyncItems( const Item::List &changedItems, - const Item::List &removedItems ); - - /** - * Sets the item fetch scope. - * - * The ItemFetchScope controls how much of an item's data is fetched - * from the server, e.g. whether to fetch the full item payload or - * only meta data. - * - * @param fetchScope The new scope for item fetch operations. - * - * @see fetchScope() - */ - void setFetchScope( ItemFetchScope &fetchScope ); - - /** - * Returns the item fetch scope. - * - * Since this returns a reference it can be used to conveniently modify the - * current scope in-place, i.e. by calling a method on the returned reference - * without storing it in a local variable. See the ItemFetchScope documentation - * for an example. - * - * @return a reference to the current item fetch scope - * - * @see setFetchScope() for replacing the current item fetch scope - */ - ItemFetchScope &fetchScope(); - - protected: - void doStart(); - - /** - * Reimplement this method to customize the synchronization algorithm. - * - * You can update the @p newItem according to the @p storedItem before - * it gets committed. - */ - virtual bool updateItem( const Item &storedItem, Item &newItem ); - - private: - //@cond PRIVATE - class Private; - Private* const d; - - Q_PRIVATE_SLOT( d, void slotLocalListDone( KJob* ) ) - Q_PRIVATE_SLOT( d, void slotLocalChangeDone( KJob* ) ) - Q_PRIVATE_SLOT( d, void slotTransactionResult( KJob* ) ) - //@endcond -}; - -} - -#endif diff --git a/akonadi/itemview.cpp b/akonadi/itemview.cpp deleted file mode 100644 index 4c9a20abc..000000000 --- a/akonadi/itemview.cpp +++ /dev/null @@ -1,144 +0,0 @@ -/* - Copyright (c) 2007 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - - -#include "itemview.h" - -#include "itemmodel.h" - -#include -#include - -#include -#include -#include - -using namespace Akonadi; - -/** - * @internal - */ -class ItemView::Private -{ - public: - Private( ItemView *parent ) : - xmlGuiWindow( 0 ), - mParent( parent ) - { - } - - void init(); - void itemActivated( const QModelIndex& ); - void itemCurrentChanged( const QModelIndex& ); - - KXmlGuiWindow *xmlGuiWindow; - - private: - ItemView *mParent; -}; - -void ItemView::Private::init() -{ - mParent->setRootIsDecorated( false ); - - mParent->header()->setClickable( true ); - mParent->header()->setStretchLastSection( true ); - - mParent->connect( mParent, SIGNAL( activated( const QModelIndex& ) ), - mParent, SLOT( itemActivated( const QModelIndex& ) ) ); -} - -void ItemView::Private::itemActivated( const QModelIndex &index ) -{ - if ( !index.isValid() ) - return; - - const Item::Id currentItem = index.sibling(index.row(),ItemModel::Id).data(ItemModel::IdRole).toLongLong(); - if ( currentItem <= 0 ) - return; - - const QString remoteId = index.sibling(index.row(),ItemModel::RemoteId).data(ItemModel::IdRole).toString(); - - Item item( currentItem ); - item.setRemoteId( remoteId ); - - emit mParent->activated( item ); -} - -void ItemView::Private::itemCurrentChanged( const QModelIndex &index ) -{ - if ( !index.isValid() ) - return; - - const Item::Id currentItem = index.sibling(index.row(),ItemModel::Id).data(ItemModel::IdRole).toLongLong(); - if ( currentItem <= 0 ) - return; - - const QString remoteId = index.sibling(index.row(),ItemModel::RemoteId).data(ItemModel::IdRole).toString(); - - Item item( currentItem ); - item.setRemoteId( remoteId ); - - emit mParent->currentChanged( item ); -} - -ItemView::ItemView( QWidget * parent ) : - QTreeView( parent ), - d( new Private( this ) ) -{ - d->init(); -} - -ItemView::ItemView(KXmlGuiWindow * xmlGuiWindow, QWidget * parent) : - QTreeView( parent ), - d( new Private( this ) ) -{ - d->xmlGuiWindow = xmlGuiWindow; - d->init(); -} - -ItemView::~ItemView() -{ - delete d; -} - -void ItemView::setModel( QAbstractItemModel * model ) -{ - QTreeView::setModel( model ); - - connect( selectionModel(), SIGNAL( currentChanged( const QModelIndex&, const QModelIndex& ) ), - this, SLOT( itemCurrentChanged( const QModelIndex& ) ) ); -} - -void ItemView::contextMenuEvent(QContextMenuEvent * event) -{ - if ( !d->xmlGuiWindow ) - return; - QMenu *popup = static_cast( d->xmlGuiWindow->guiFactory()->container( - QLatin1String("akonadi_itemview_contextmenu"), d->xmlGuiWindow ) ); - if ( popup ) - popup->exec( event->globalPos() ); -} - -void ItemView::setXmlGuiWindow(KXmlGuiWindow * xmlGuiWindow) -{ - d->xmlGuiWindow = xmlGuiWindow; -} - -#include "itemview.moc" diff --git a/akonadi/itemview.h b/akonadi/itemview.h deleted file mode 100644 index 77eff8f93..000000000 --- a/akonadi/itemview.h +++ /dev/null @@ -1,130 +0,0 @@ -/* - Copyright (c) 2007 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_ITEM_VIEW -#define AKONADI_ITEM_VIEW - -#include "akonadi_export.h" -#include - -class KXmlGuiWindow; - -namespace Akonadi { - -class Item; - -/** - * @short A view to show an item list provided by an ItemModel. - * - * When a KXmlGuiWindow is set, the XMLGUI defined context menu - * @c akonadi_itemview_contextmenu is used if available. - * - * Example: - * - * @code - * - * class MyWindow : public KXmlGuiWindow - * { - * public: - * MyWindow() - * : KXmlGuiWindow() - * { - * Akonadi::ItemView *view = new Akonadi::ItemView( this, this ); - * setCentralWidget( view ); - * - * Akonadi::ItemModel *model = new Akonadi::ItemModel( this ); - * view->setModel( model ); - * } - * } - * - * @endcode - * - * @author Tobias Koenig - */ -class AKONADI_EXPORT ItemView : public QTreeView -{ - Q_OBJECT - - public: - /** - * Creates a new item view. - * - * @param parent The parent widget. - */ - explicit ItemView( QWidget *parent = 0 ); - - /** - * Creates a new item view. - * - * @param xmlGuiWindow The KXmlGuiWindow this is used in. - * This is needed for the XMLGUI based context menu. - * Passing 0 is ok and will disable the builtin context menu. - * @param parent The parent widget. - */ - explicit ItemView( KXmlGuiWindow *xmlGuiWindow, QWidget *parent = 0 ); - - /** - * Destroys the item view. - */ - virtual ~ItemView(); - - /** - * Sets the KXmlGuiWindow which this view is used in. - * This is needed if you want to use the built-in context menu. - * - * @param xmlGuiWindow The KXmlGuiWindow this view is used in. - */ - void setXmlGuiWindow( KXmlGuiWindow *xmlGuiWindow ); - - virtual void setModel( QAbstractItemModel * model ); - - Q_SIGNALS: - /** - * This signal is emitted whenever the user has activated - * an item in the view. - * - * @param item The activated item. - */ - void activated( const Akonadi::Item &item ); - - /** - * This signal is emitted whenever the current item - * in the view has changed. - * - * @param item The current item. - */ - void currentChanged( const Akonadi::Item &item ); - - protected: - using QTreeView::currentChanged; - void contextMenuEvent( QContextMenuEvent *event ); - - private: - //@cond PRIVATE - class Private; - Private * const d; - - Q_PRIVATE_SLOT( d, void itemActivated( const QModelIndex& ) ) - Q_PRIVATE_SLOT( d, void itemCurrentChanged( const QModelIndex& ) ) - //@endcond -}; - -} - -#endif diff --git a/akonadi/job.cpp b/akonadi/job.cpp deleted file mode 100644 index 954ab82de..000000000 --- a/akonadi/job.cpp +++ /dev/null @@ -1,246 +0,0 @@ -/* - Copyright (c) 2006 Tobias Koenig - 2006 Marc Mutz - 2006 - 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "job.h" -#include "job_p.h" -#include "imapparser_p.h" -#include "session.h" -#include "session_p.h" - -#include -#include - -#include -#include -#include -#include -#include - -using namespace Akonadi; - -//@cond PRIVATE -void JobPrivate::handleResponse( const QByteArray & tag, const QByteArray & data ) -{ - Q_Q( Job ); - - if ( mCurrentSubJob ) { - mCurrentSubJob->d_ptr->handleResponse( tag, data ); - return; - } - - if ( tag == mTag ) { - if ( data.startsWith( "NO " ) || data.startsWith( "BAD " ) ) { - QString msg = QString::fromUtf8( data ); - - msg.remove( 0, msg.startsWith( QLatin1String( "NO " ) ) ? 3 : 4 ); - - if ( msg.endsWith( QLatin1String( "\r\n" ) ) ) - msg.chop( 2 ); - - q->setError( Job::Unknown ); - q->setErrorText( msg ); - q->emitResult(); - return; - } else if ( data.startsWith( "OK" ) ) { - q->emitResult(); - return; - } - } - - q->doHandleResponse( tag, data ); -} - -void JobPrivate::init( QObject *parent ) -{ - Q_Q( Job ); - - mParentJob = dynamic_cast( parent ); - mSession = dynamic_cast( parent ); - - if ( !mSession ) { - if ( !mParentJob ) - mSession = Session::defaultSession(); - else - mSession = mParentJob->d_ptr->mSession; - } - - if ( !mParentJob ) - mSession->d->addJob( q ); - else - mParentJob->addSubjob( q ); -} - -void JobPrivate::startQueued() -{ - Q_Q( Job ); - mStarted = true; - - emit q->aboutToStart( q ); - q->doStart(); - QTimer::singleShot( 0, q, SLOT(startNext()) ); -} - -void JobPrivate::lostConnection() -{ - Q_Q( Job ); - - if ( mCurrentSubJob ) { - mCurrentSubJob->d_ptr->lostConnection(); - } else { - q->setError( Job::ConnectionFailed ); - q->kill( KJob::EmitResult ); - } -} - -void JobPrivate::slotSubJobAboutToStart( Job * job ) -{ - Q_ASSERT( mCurrentSubJob == 0 ); - mCurrentSubJob = job; -} - -void JobPrivate::startNext() -{ - Q_Q( Job ); - - if ( mStarted && !mCurrentSubJob && q->hasSubjobs() ) { - Job *job = dynamic_cast( q->subjobs().first() ); - Q_ASSERT( job ); - job->d_ptr->startQueued(); - } -} - -QByteArray JobPrivate::newTag( ) -{ - if ( mParentJob ) - mTag = mParentJob->d_ptr->newTag(); - else - mTag = QByteArray::number( mSession->d->nextTag() ); - return mTag; -} - -QByteArray JobPrivate::tag() const -{ - return mTag; -} - -void JobPrivate::writeData( const QByteArray & data ) -{ - Q_ASSERT_X( !mWriteFinished, "Job::writeData()", "Calling writeData() after emitting writeFinished()" ); - mSession->d->writeData( data ); -} -//@endcond - - -Job::Job( QObject *parent ) - : KCompositeJob( parent ), - d_ptr( new JobPrivate( this ) ) -{ - d_ptr->init( parent ); -} - -Job::Job( JobPrivate *dd, QObject *parent ) - : KCompositeJob( parent ), - d_ptr( dd ) -{ - d_ptr->init( parent ); -} - -Job::~Job() -{ - delete d_ptr; -} - -void Job::start() -{ -} - -bool Job::doKill() -{ - return true; -} - -QString Job::errorString() const -{ - QString str; - switch ( error() ) { - case NoError: - break; - case ConnectionFailed: - str = i18n( "Cannot connect to the Akonadi service." ); - break; - case ProtocolVersionMismatch: - str = i18n( "The protocol version of the Akonadi server is incompatible. Make sure you have a compatible version installed." ); - break; - case UserCanceled: - str = i18n( "User canceled operation." ); - break; - case Unknown: - default: - str = i18n( "Unknown error." ); - break; - } - if ( !errorText().isEmpty() ) { - str += QString::fromLatin1( " (%1)" ).arg( errorText() ); - } - return str; -} - -bool Job::addSubjob( KJob * job ) -{ - bool rv = KCompositeJob::addSubjob( job ); - if ( rv ) { - connect( job, SIGNAL(aboutToStart(Akonadi::Job*)), SLOT(slotSubJobAboutToStart(Akonadi::Job*)) ); - QTimer::singleShot( 0, this, SLOT(startNext()) ); - } - return rv; -} - -bool Job::removeSubjob(KJob * job) -{ - bool rv = KCompositeJob::removeSubjob( job ); - if ( job == d_ptr->mCurrentSubJob ) { - d_ptr->mCurrentSubJob = 0; - QTimer::singleShot( 0, this, SLOT(startNext()) ); - } - return rv; -} - -void Job::doHandleResponse(const QByteArray & tag, const QByteArray & data) -{ - kDebug( 5250 ) << "Unhandled response: " << tag << data; -} - -void Job::slotResult(KJob * job) -{ - Q_ASSERT( job == d_ptr->mCurrentSubJob ); - d_ptr->mCurrentSubJob = 0; - KCompositeJob::slotResult( job ); - if ( !job->error() ) - QTimer::singleShot( 0, this, SLOT(startNext()) ); -} - -void Job::emitWriteFinished() -{ - d_ptr->mWriteFinished = true; - emit writeFinished( this ); -} - -#include "job.moc" diff --git a/akonadi/job.h b/akonadi/job.h deleted file mode 100644 index b224fac42..000000000 --- a/akonadi/job.h +++ /dev/null @@ -1,233 +0,0 @@ -/* - Copyright (c) 2006 Tobias Koenig - 2006 Marc Mutz - 2006 - 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_JOB_H -#define AKONADI_JOB_H - -#include "akonadi_export.h" - -#include - -class QString; - -namespace Akonadi { - -class JobPrivate; -class Session; -class SessionPrivate; - -/** - * @short Base class for all actions in the Akonadi storage. - * - * This class encapsulates a request to the pim storage service, - * the code looks like - * - * @code - * - * Akonadi::Job *job = new Akonadi::SomeJob( some parameter ); - * connect( job, SIGNAL( result( KJob* ) ), - * this, SLOT( slotResult( KJob* ) ) ); - * - * @endcode - * - * The job is queued for execution as soon as the event loop is entered - * again. - * - * And the slotResult is usually at least: - * - * @code - * - * if ( job->error() ) { - * // handle error... - * } - * - * @endcode - * - * With the synchronous interface the code looks like - * - * @code - * Akonadi::SomeJob *job = new Akonadi::SomeJob( some parameter ); - * if ( !job->exec() ) { - * qDebug() << "Error:" << job->errorString(); - * } else { - * // do something - * } - * @endcode - * - * @warning Using the synchronous method is error prone, use this only - * if the asynchronous access is not possible and none of the following - * known issues apply: - * - * - exec() must not be called directly from a result slot of another - * job in the same Session. This will trigger a dead-lock since the - * program won't return from the result slot and thus will never complete - * the finishing of the current job, keeping it in the internal queue - * and blocking the execution of any following job. - * - exec() must not be called from within another event-loop that might - * finish before the newly started inner sub-eventloop. This will crash! - * - * Subclasses must reimplement doStart(). - * - * @note KJob-derived objects delete itself, it is thus not possible - * to create job objects on the stack! - * - * @author Volker Krause , Tobias Koenig , Marc Mutz - */ -class AKONADI_EXPORT Job : public KCompositeJob -{ - Q_OBJECT - - friend class Session; - friend class SessionPrivate; - - public: - /** - * Describes a list of jobs. - */ - typedef QList List; - - /** - * Describes the error codes that can be emitted by this class. - * Subclasses can provide additional codes, starting from UserError - * onwards - */ - enum Error - { - ConnectionFailed = UserDefinedError, ///< The connection to the Akonadi server failed. - ProtocolVersionMismatch, ///< The server protocol version is too old or too new. - UserCanceled, ///< The user canceld this job. - Unknown, ///< Unknown error. - UserError = UserDefinedError + 42 ///< Starting point for error codes defined by sub-classes. - }; - - /** - * Creates a new job. - * - * If the parent object is a Job object, the new job will be a subjob of @p parent. - * If the parent object is a Session object, it will be used for server communication - * instead of the default session. - * - * @param parent The parent object, job or session. - */ - explicit Job( QObject *parent = 0 ); - - /** - * Destroys the job. - */ - virtual ~Job(); - - /** - * Jobs are started automatically once entering the event loop again, no need - * to explicitly call this. - */ - void start(); - - /** - * Returns the error string, if there has been an error, an empty - * string otherwise. - */ - virtual QString errorString() const; - - Q_SIGNALS: - /** - * This signal is emitted directly before the job will be started. - * - * @param job The started job. - */ - void aboutToStart( Akonadi::Job *job ); - - /** - * This signal is emitted if the job has finished all write operations, ie. - * if this signal is emitted, the job guarantees to not call writeData() again. - * Do not emit this signal directly, call emitWriteFinished() instead. - * - * @param job This job. - * @see emitWriteFinished() - */ - void writeFinished( Akonadi::Job *job ); - - protected: - /** - * This method must be reimplemented in the concrete jobs. It will be called - * after the job has been started and a connection to the Akonadi backend has - * been established. - */ - virtual void doStart() = 0; - - /** - * This method should be reimplemented in the concrete jobs in case you want - * to handle incoming data. It will be called on received data from the backend. - * The default implementation does nothing. - * - * @param tag The tag of the corresponding command, empty if this is an untagged response. - * @param data The received data. - */ - virtual void doHandleResponse( const QByteArray &tag, const QByteArray &data ); - - /** - * Adds the given job as a subjob to this job. This method is automatically called - * if you construct a job using another job as parent object. - * The base implementation does the necessary setup to share the network connection - * with the backend. - * - * @param job The new subjob. - */ - virtual bool addSubjob( KJob* job ); - - /** - * Removes the given subjob of this job. - * - * @param job The subjob to remove. - */ - virtual bool removeSubjob( KJob* job ); - - /** - * Kills the execution of the job. - */ - virtual bool doKill(); - - /** - * Call this method to indicate that this job will not call writeData() again. - * @see writeFinished() - */ - void emitWriteFinished(); - - protected Q_SLOTS: - virtual void slotResult( KJob* job ); - - protected: - //@cond PRIVATE - Job( JobPrivate *dd, QObject *parent ); - JobPrivate* const d_ptr; - //@endcond - - private: - Q_DECLARE_PRIVATE( Job ) - - //@cond PRIVATE - Q_PRIVATE_SLOT( d_func(), void slotSubJobAboutToStart( Akonadi::Job* ) ) - Q_PRIVATE_SLOT( d_func(), void startNext() ) - //@endcond -}; - -} - -#endif diff --git a/akonadi/job_p.h b/akonadi/job_p.h deleted file mode 100644 index d7ff33a91..000000000 --- a/akonadi/job_p.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - Copyright (c) 2007 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_JOB_P_H -#define AKONADI_JOB_P_H - -#include "session.h" - -namespace Akonadi { - -/** - * @internal - */ -class JobPrivate -{ - public: - JobPrivate( Job *parent ) - : q_ptr( parent ), - mCurrentSubJob( 0 ), - mWriteFinished( false ), - mStarted( false ) - { - } - - virtual ~JobPrivate() - { - } - - void init( QObject *parent ); - - void handleResponse( const QByteArray &tag, const QByteArray &data ); - void startQueued(); - void lostConnection(); - void slotSubJobAboutToStart( Akonadi::Job* ); - void startNext(); - /** - Returns a new unique command tag for communication with the backend. - */ - QByteArray newTag(); - - /** - Return the tag used for the request. - */ - QByteArray tag() const; - - /** - Sends raw data to the backend. - */ - void writeData( const QByteArray &data ); - - Job *q_ptr; - Q_DECLARE_PUBLIC( Job ) - - Job *mParentJob; - Job *mCurrentSubJob; - QByteArray mTag; - Session* mSession; - bool mWriteFinished; - bool mStarted; -}; - -} - -#endif diff --git a/akonadi/kcfg2dbus.xsl b/akonadi/kcfg2dbus.xsl deleted file mode 100644 index d79c8827d..000000000 --- a/akonadi/kcfg2dbus.xsl +++ /dev/null @@ -1,100 +0,0 @@ - - - - -interfaceName - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - s - as - ? - (iiii) - (ii) - ? - (ii) - i - u - b - d - ((iii)(iiii)i) - x - t - ai - i - s - as - s - s - as - v - - - - - - QRect - QSize - QPoint - QDateTime - - - - - \ No newline at end of file diff --git a/akonadi/kmime/CMakeLists.txt b/akonadi/kmime/CMakeLists.txt deleted file mode 100644 index ab7727373..000000000 --- a/akonadi/kmime/CMakeLists.txt +++ /dev/null @@ -1,33 +0,0 @@ -include_directories( - ${CMAKE_SOURCE_DIR}/ - ${QT_QTDBUS_INCLUDE_DIR} - ${Boost_INCLUDE_DIR} -) - -set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII ${KDE4_ENABLE_EXCEPTIONS}" ) - -########### next target ############### - -set( kmimeakonadi_LIB_SRC - messagemodel.cpp - messageparts.cpp - messagethreadingattribute.cpp - messagethreaderproxymodel.cpp -) - -kde4_add_library( akonadi-kmime SHARED ${kmimeakonadi_LIB_SRC} ) - -target_link_libraries( akonadi-kmime akonadi-kde kmime ${QT_QTGUI_LIBRARY} ${KDE4_KDECORE_LIBS} ) -set_target_properties( akonadi-kmime PROPERTIES VERSION ${GENERIC_LIB_VERSION} SOVERSION ${GENERIC_LIB_SOVERSION} ) -install(TARGETS akonadi-kmime ${INSTALL_TARGETS_DEFAULT_ARGS}) - -########### install files ############### - -install( FILES - akonadi-kmime_export.h - messagemodel.h - messageparts.h - messagethreadingattribute.h - messagethreaderproxymodel.h - DESTINATION ${INCLUDE_INSTALL_DIR}/akonadi/kmime COMPONENT Devel -) diff --git a/akonadi/kmime/akonadi-kmime_export.h b/akonadi/kmime/akonadi-kmime_export.h deleted file mode 100644 index 7a8a58be7..000000000 --- a/akonadi/kmime/akonadi-kmime_export.h +++ /dev/null @@ -1,36 +0,0 @@ -/* This file is part of the KDE project - Copyright (C) 2007 David Faure - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef AKONADI_KMIME_EXPORT_H -#define AKONADI_KMIME_EXPORT_H - -/* needed for KDE_EXPORT and KDE_IMPORT macros */ -#include - -#ifndef AKONADI_KMIME_EXPORT -# if defined(MAKE_AKONADI_KMIME_LIB) - /* We are building this library */ -# define AKONADI_KMIME_EXPORT KDE_EXPORT -# else - /* We are using this library */ -# define AKONADI_KMIME_EXPORT KDE_IMPORT -# endif -#endif - -#endif diff --git a/akonadi/kmime/messagemodel.cpp b/akonadi/kmime/messagemodel.cpp deleted file mode 100644 index ec87dafb5..000000000 --- a/akonadi/kmime/messagemodel.cpp +++ /dev/null @@ -1,131 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "messagemodel.h" -#include "messageparts.h" - -#include -#include -#include - -#include -#include -typedef boost::shared_ptr MessagePtr; - -#include -#include -#include - -#include - -using namespace Akonadi; - -class Akonadi::MessageModel::Private -{ - public: -}; - -MessageModel::MessageModel( QObject *parent ) : - ItemModel( parent ), - d( new Private() ) -{ - fetchScope().fetchPayloadPart( MessagePart::Envelope ); -} - -MessageModel::~MessageModel( ) -{ - delete d; -} - -int MessageModel::columnCount( const QModelIndex & parent ) const -{ - if ( !parent.isValid() ) - return 5; // keep in sync with the column type enum - - return 0; -} - -QVariant MessageModel::data( const QModelIndex & index, int role ) const -{ - if ( !index.isValid() ) - return QVariant(); - if ( index.row() >= rowCount() ) - return QVariant(); - Item item = itemForIndex( index ); - if ( !item.hasPayload() ) - return QVariant(); - MessagePtr msg = item.payload(); - if ( role == Qt::DisplayRole ) { - switch ( index.column() ) { - case Subject: - return msg->subject()->asUnicodeString(); - case Sender: - return msg->from()->asUnicodeString(); - case Receiver: - return msg->to()->asUnicodeString(); - case Date: - return KGlobal::locale()->formatDateTime( msg->date()->dateTime().toLocalZone(), KLocale::FancyLongDate ); - case Size: - // TODO - return 0; // pass modeltest - default: - return QVariant(); - } - } else if ( role == Qt::EditRole ) { - switch ( index.column() ) { - case Subject: - return msg->subject()->asUnicodeString(); - case Sender: - return msg->from()->asUnicodeString(); - case Receiver: - return msg->to()->asUnicodeString(); - case Date: - return msg->date()->dateTime().dateTime(); - case Size: - // TODO - return 0; // pass modeltest - default: - return QVariant(); - } - } - return ItemModel::data( index, role ); -} - -QVariant MessageModel::headerData( int section, Qt::Orientation orientation, int role ) const -{ - if ( orientation == Qt::Horizontal && role == Qt::DisplayRole ) { - switch ( section ) { - case Subject: - return i18nc( "@title:column, message (e.g. email) subject", "Subject" ); - case Sender: - return i18nc( "@title:column, sender of message (e.g. email)", "Sender" ); - case Receiver: - return i18nc( "@title:column, receiver of message (e.g. email)", "Receiver" ); - case Date: - return i18nc( "@title:column, message (e.g. email) timestamp", "Date" ); - case Size: - return i18nc( "@title:column, message (e.g. email) size", "Size" ); - default: - return QString(); - } - } - return ItemModel::headerData( section, orientation, role ); -} - -#include "messagemodel.moc" diff --git a/akonadi/kmime/messagemodel.h b/akonadi/kmime/messagemodel.h deleted file mode 100644 index 8937269e8..000000000 --- a/akonadi/kmime/messagemodel.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_MESSAGEMODEL_H -#define AKONADI_MESSAGEMODEL_H - -#include "akonadi-kmime_export.h" -#include -#include - -namespace Akonadi { - -/** - A flat self-updating message model. -*/ -class AKONADI_KMIME_EXPORT MessageModel : public Akonadi::ItemModel -{ - Q_OBJECT - - public: - /** - Column types. - */ - enum Column { - Subject, /**< Subject column. */ - Sender, /**< Sender column. */ - Receiver, /**< Receiver column. */ - Date, /**< Date column. */ - Size /**< Size column. */ - }; - - /** - Creates a new message model. - - @param parent The parent object. - */ - explicit MessageModel( QObject* parent = 0 ); - - /** - Deletes the message model. - */ - virtual ~MessageModel(); - - /** - Reimplemented from QAbstractItemModel. - */ - virtual int columnCount( const QModelIndex & parent = QModelIndex() ) const; - - /** - Reimplemented from QAbstractItemModel. - */ - virtual QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) const; - - /** - Reimplemented from QAbstractItemModel. - */ - virtual QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; - - private: - class Private; - Private* const d; -}; - -} - -#endif diff --git a/akonadi/kmime/messageparts.cpp b/akonadi/kmime/messageparts.cpp deleted file mode 100644 index 09d03a1b8..000000000 --- a/akonadi/kmime/messageparts.cpp +++ /dev/null @@ -1,25 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - 2007 Till Adam - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "messageparts.h" - -const char* Akonadi::MessagePart::Envelope = "ENVELOPE"; -const char* Akonadi::MessagePart::Body = "RFC822"; -const char* Akonadi::MessagePart::Header = "HEAD"; diff --git a/akonadi/kmime/messageparts.h b/akonadi/kmime/messageparts.h deleted file mode 100644 index 470132524..000000000 --- a/akonadi/kmime/messageparts.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - 2007 Till Adam - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_MESSAGEPARTS_H -#define AKONADI_MESSAGEPARTS_H - -#include "akonadi-kmime_export.h" - -namespace Akonadi -{ - /** - * @short Contains predefined part identifiers. - * - * This namespace contains identifiers of item parts that are used for - * handling email items. - */ - namespace MessagePart - { - /** - * The part identifier for envelope parts. - */ - AKONADI_KMIME_EXPORT extern const char* Envelope; - - /** - * The part identifier for the main body part. - */ - AKONADI_KMIME_EXPORT extern const char* Body; - - /** - * The part identifier for the header part. - */ - AKONADI_KMIME_EXPORT extern const char* Header; - } -} - -#endif diff --git a/akonadi/kmime/messagethreaderproxymodel.cpp b/akonadi/kmime/messagethreaderproxymodel.cpp deleted file mode 100644 index 2aca81054..000000000 --- a/akonadi/kmime/messagethreaderproxymodel.cpp +++ /dev/null @@ -1,392 +0,0 @@ -/* - Copyright (c) 2007 Bruno Virlet - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "messagethreaderproxymodel.h" -#include "messagethreadingattribute.h" -#include "messagemodel.h" - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -using namespace Akonadi; - -class MessageThreaderProxyModel::Private -{ - public: - Private( MessageThreaderProxyModel *parent ) - : mParent( parent ) - { - } - - - MessageModel* sourceMessageModel() - { - return dynamic_cast( mParent->sourceModel() ); - } - - /* - * Reset everything - */ - void slotCollectionChanged() - { - childrenMap.clear(); - indexMap.clear(); - parentMap.clear(); - realPerfectParentsMap.clear(); - realUnperfectParentsMap.clear(); - realSubjectParentsMap.clear(); - - realPerfectChildrenMap.clear(); - realUnperfectChildrenMap.clear(); - realSubjectChildrenMap.clear(); - - mParent->reset(); - } - - /* - * Function called when the signal rowsInserted was triggered in the - * source model. - */ - void slotInsertRows( const QModelIndex& sourceIndex, int begin, int end ) - { - Q_UNUSED( sourceIndex ); // parent source index is always invalid (flat source model) - QTime time; - time.start(); - - for ( int i=begin; i <= end; i++ ) - { - // Retrieve the item from the source model - Item item = sourceMessageModel()->itemForIndex( sourceMessageModel()->index( i, 0 ) ); - Entity::Id id = item.id(); - // Get his best potential parent using the mail threader parts - readParentsFromParts( item ); - Entity::Id parentId = parentForItem( item.id() ); - - /* - * Fill in the tree maps - */ - int row = childrenMap[ parentId ].count(); - mParent->beginInsertRows( indexMap[ parentId ], row, row ); - childrenMap[ parentId ] << item.id(); - parentMap[ id ] = parentId; - QModelIndex index = mParent->createIndex( childrenMap[ parentId ].count() - 1, 0, id ); - mParent->endInsertRows(); - - - /* - * Look for potential children into real children map - */ - QList potentialChildren = realPerfectChildrenMap[ id ] - << realUnperfectChildrenMap[ id ] - << realSubjectChildrenMap[ id ]; - foreach( Entity::Id potentialChildId, potentialChildren ) { - // This item can be a child of our item if: - // - it's not the item itself (could we do that check when building the 'real' maps ?) - // - his parent is set - // - and this parent is not already our item - if ( potentialChildId != id && - parentMap.constFind( potentialChildId ) != parentMap.constEnd() && - parentMap[ potentialChildId ] != id && - parentMap[ potentialChildId ] - ) - - { - // Check that the current parent of this item is not better than ours - QList realParentsList = realPerfectParentsMap[ potentialChildId ] - << realUnperfectParentsMap[ potentialChildId ] - << realSubjectParentsMap[ potentialChildId ]; - int currentParentPos = realParentsList.indexOf( parentMap[ potentialChildId ] ); - // currentParentPos = 0 is probably the more common case so we may avoid an indexOf. - if ( currentParentPos == 0 || ( currentParentPos != -1 && realParentsList.indexOf( id ) > currentParentPos ) ) - // (currentParentPos can be -1 if parent is root) - continue; - - // Remove the children from the old location - int childRow = childrenMap[ parentMap[ potentialChildId ] ].indexOf( potentialChildId ); - mParent->beginRemoveRows( indexMap[ parentMap[ potentialChildId ] ], childRow, childRow ); - mParent->endRemoveRows(); - childrenMap[ parentMap[ potentialChildId ] ].removeAt( childRow ); - - // Change the tree info - mParent->beginInsertRows( index, childrenMap[ id ].count(), childrenMap[ id ].count() ); - parentMap[ potentialChildId ] = id; - childrenMap[ id ] << potentialChildId; - - // Recreate index because row change - mParent->createIndex( childrenMap[ id ].count() - 1, 0, potentialChildId ); - mParent->endInsertRows(); - } - } - } - - qDebug() << time.elapsed() << "ms for" << end - begin + 1 << "items"; - } - - /* - * Function called when the signal rowsAboutToBeRemoved is sent by the source model - * (source model indexes are *still* valid) - */ - void slotRemoveRows( const QModelIndex& sourceIndex, int begin, int end ) - { - Q_UNUSED( sourceIndex ); - for ( int i = begin; i <= end; i++ ) - { - Item item = sourceMessageModel()->itemForIndex( sourceMessageModel()->index( i, 0 ) ); - Entity::Id id = item.id(); - Entity::Id parentId = parentMap[ id ]; - int row = childrenMap[ parentId ].indexOf( id ); - - // Reparent the children to the closest parent - foreach( Entity::Id childId, childrenMap[ id ] ) { - int childRow = childrenMap[ id ].indexOf( childId ); - mParent->beginRemoveRows( indexMap[ id ], childRow, childRow ); - childrenMap[ id ].removeAll( childId ); // There is only one ... - mParent->endRemoveRows(); - - mParent->beginInsertRows( indexMap[ parentId ], childrenMap[ parentId ].count(), - childrenMap[ parentId ].count() ); - parentMap[ childId ] = parentId; - childrenMap[ parentId ] << childId; - mParent->endInsertRows(); - - mParent->createIndex( childrenMap[ parentId ].count() - 1, 0, childId ); // Is it necessary to recreate the index ? - } - - mParent->beginRemoveRows( indexMap[ parentId ], row, row ); - childrenMap[ parentId ].removeAll( id ); // Remove this id from the children of parentId - parentMap.remove( id ); - indexMap.remove( id ); - mParent->endRemoveRows(); -// mParent->beginRemoveColumns( indexMap[ parentId ], 0, sourceMessageModel()->columnCount() - 1 ); -// mParent->endRemoveColumns(); - } - } - - /* - * This item has his parents stored in his threading parts. - * Read them and store them in the 'real' maps. - * - * We store both relationships : - * - child -> parents ( real*ParentsMap ) - * - parent -> children ( real*ChildrenMap ) - */ - void readParentsFromParts( const Item& item ) - { - MessageThreadingAttribute *attr = item.attribute(); - if ( attr ) { - QList realPerfectParentsList = attr->perfectParents(); - QList realUnperfectParentsList = attr->unperfectParents(); - QList realSubjectParentsList = attr->subjectParents(); - - realPerfectParentsMap[ item.id() ] = realPerfectParentsList; - realUnperfectParentsMap[ item.id() ] = realUnperfectParentsList; - realSubjectParentsMap[ item.id() ] = realSubjectParentsList; - - // Fill in the children maps - foreach( Entity::Id parentId, realPerfectParentsList ) - realPerfectChildrenMap[ parentId ] << item.id(); - foreach( Entity::Id parentId, realUnperfectParentsList ) - realUnperfectChildrenMap[ parentId ] << item.id(); - foreach( Entity::Id parentId, realSubjectParentsList ) - realSubjectChildrenMap[ parentId ] << item.id(); - } - } - - /* - * Find the first parent in the parents maps which is actually in the current collection - * @param id the item id - * @returns the parent id - */ - Entity::Id parentForItem( Entity::Id id ) - { - - QList parentsIds; - parentsIds << realPerfectParentsMap[ id ] << realUnperfectParentsMap[ id ] << realSubjectParentsMap[ id ]; - - foreach( Entity::Id parentId, parentsIds ) - { - // Check that the parent is in the collection - // This is time consuming but ... required. - if ( sourceMessageModel()->indexForItem( Item( parentId ), 0 ).isValid() ) - return parentId; - - } - - // TODO Check somewhere for 'parent loops' : in the parts, an item child of his child ... - return -1; - } - - // -1 is an invalid id which means 'root' - Entity::Id idForIndex( const QModelIndex& index ) - { - return index.isValid() ? index.internalId() : -1; - } - - MessageThreaderProxyModel *mParent; - - /* - * These maps store the current tree structure, as presented in the view. - * It tries to be as close as possible from the real structure, given that not every parents - * are present in the collection - */ - QHash > childrenMap; - QHash parentMap; - QHash indexMap; - - /* - * These maps store the real parents, as read from the item parts - * In the best case, the list should contain only one element ( = unique parent ) - * If there isn't only one, the algorithm will pick up the first one in the current collection - */ - QHash > realPerfectParentsMap; - QHash > realUnperfectParentsMap; - QHash > realSubjectParentsMap; - - QHash > realPerfectChildrenMap; - QHash > realUnperfectChildrenMap; - QHash > realSubjectChildrenMap; -}; - -MessageThreaderProxyModel::MessageThreaderProxyModel( QObject *parent ) - : QAbstractProxyModel( parent ), - d( new Private( this ) ) -{ - AttributeFactory::registerAttribute(); - setSupportedDragActions( Qt::MoveAction | Qt::CopyAction ); -} - -MessageThreaderProxyModel::~MessageThreaderProxyModel() -{ - delete d; -} - -QModelIndex MessageThreaderProxyModel::index( int row, int column, const QModelIndex& parent ) const -{ - Entity::Id parentId = d->idForIndex( parent ); - - if ( row < 0 - || column < 0 - || row >= d->childrenMap[ parentId ].count() - || column >= columnCount( parent ) - ) - return QModelIndex(); - - Entity::Id id = d->childrenMap[ parentId ].at( row ); - - return createIndex( row, column, id ); -} - -QModelIndex MessageThreaderProxyModel::parent( const QModelIndex & index ) const -{ - if ( !index.isValid() ) - return QModelIndex(); - - Entity::Id parentId = d->parentMap[ index.internalId() ]; - - if ( parentId == -1 ) - return QModelIndex(); - -// int parentParentId = d->parentMap[ parentId ]; - //int row = d->childrenMap[ parentParentId ].indexOf( parentId ); - return d->indexMap[ d->parentMap[ index.internalId() ] ]; - //return createIndex( row, 0, parentId ); -} - -QModelIndex MessageThreaderProxyModel::mapToSource( const QModelIndex& index ) const -{ - // This function is slow because it relies on rowForItem in the ItemModel (linear time) - return d->sourceMessageModel()->indexForItem( Item( index.internalId() ), index.column() ); -} - -QModelIndex MessageThreaderProxyModel::mapFromSource( const QModelIndex& index ) const -{ - Item item = d->sourceMessageModel()->itemForIndex( index ); - Entity::Id id = item.id(); - //return d->indexMap[ id ]; // FIXME take column in account like mapToSource - return MessageThreaderProxyModel::index( d->indexMap[ id ].row(), index.column(), d->indexMap[ id ].parent() ); -} - -QModelIndex MessageThreaderProxyModel::createIndex( int row, int column, quint32 internalId ) const -{ - QModelIndex index = QAbstractProxyModel::createIndex( row, column, internalId ); - if ( column == 0 ) - d->indexMap[ internalId ] = index; // Store the newly created index in the index map - return index; -} - -void MessageThreaderProxyModel::setSourceModel( QAbstractItemModel* model ) -{ - // TODO Assert model is a MessageModel - QAbstractProxyModel::setSourceModel( model ); - - d->sourceMessageModel()->fetchScope().fetchAttribute(); - - // TODO disconnect old model - connect( sourceModel(), SIGNAL( rowsInserted( QModelIndex, int, int ) ), SLOT( slotInsertRows( QModelIndex, int, int ) ) ); - connect( sourceModel(), SIGNAL( rowsAboutToBeRemoved( QModelIndex, int, int ) ), SLOT( slotRemoveRows( QModelIndex, int, int ) ) ); - connect( d->sourceMessageModel(), SIGNAL( collectionChanged( Collection ) ), SLOT( slotCollectionChanged() ) ); -} - - -bool MessageThreaderProxyModel::hasChildren( const QModelIndex& index ) const -{ - return rowCount( index ) > 0; -} - -int MessageThreaderProxyModel::columnCount( const QModelIndex& index ) const -{ - // We assume that the source model has the same number of columns for each rows - return sourceModel()->columnCount( QModelIndex() ); -} - -int MessageThreaderProxyModel::rowCount( const QModelIndex& index ) const -{ - Entity::Id id = d->idForIndex( index ); - if ( id == -1 ) - return d->childrenMap[ -1 ].count(); - - if ( index.column() == 0 ) // QModelIndex() has children - return d->childrenMap[ id ].count(); - - return 0; -} - -QStringList MessageThreaderProxyModel::mimeTypes() const -{ - return d->sourceMessageModel()->mimeTypes(); -} - -QMimeData *MessageThreaderProxyModel::mimeData(const QModelIndexList &indexes) const -{ - QModelIndexList sourceIndexes; - for (int i = 0; i < indexes.count(); i++) - sourceIndexes << mapToSource( indexes.at(i) ); - - return sourceModel()->mimeData(sourceIndexes); -} - -#include "messagethreaderproxymodel.moc" diff --git a/akonadi/kmime/messagethreaderproxymodel.h b/akonadi/kmime/messagethreaderproxymodel.h deleted file mode 100644 index 1443715a6..000000000 --- a/akonadi/kmime/messagethreaderproxymodel.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - Copyright (c) 2007 Bruno Virlet - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_MESSAGETHREADERPROXYMODEL_H -#define AKONADI_MESSAGETHREADERPROXYMODEL_H - -#include "akonadi-kmime_export.h" -#include -#include - -class QModelIndex; - -namespace Akonadi { - -class Collection; - -/** - * Proxy to thread message using the Mailthreader agent -*/ -class AKONADI_KMIME_EXPORT MessageThreaderProxyModel : public QAbstractProxyModel -{ - Q_OBJECT - - public: - /** - * Create a new MessageThreaderProxyModel - * @param parent The parent object - */ - MessageThreaderProxyModel( QObject *parent = 0 ); - - /** - * Destroy the model - **/ - virtual ~MessageThreaderProxyModel(); - - /** - * Reimplemented to actually do the threading. - */ - QModelIndex parent ( const QModelIndex & index ) const; - - /** - * Reimplemented - */ - int rowCount( const QModelIndex & index ) const; - - /** - * Reimplemented - */ - QModelIndex index( int row, int column, const QModelIndex& parent ) const; - - /** - * Reimplemented - */ - bool hasChildren( const QModelIndex& index ) const; - - /** - * Reimplemented - */ - QModelIndex createIndex( int row, int column, quint32 internalId ) const; - - /** - * Reimplemented - */ - int columnCount( const QModelIndex& index ) const; - - /** - * Reimplemented - */ - QStringList mimeTypes() const; - - /** - * Reimplemented - */ - QMimeData *mimeData(const QModelIndexList &indexes) const; - - /** - * Reimplemented - */ - QModelIndex mapFromSource( const QModelIndex& index ) const; - - /** - * Reimplemented - */ - QModelIndex mapToSource(const QModelIndex& index ) const; - - /** - * Set the source model. - * @param sourceMessageModel the source model. - * Be careful, sourceMessageModel has to be a MessageModel. - */ - void setSourceModel( QAbstractItemModel *sourceMessageModel ); - - private: - class Private; - Private* const d; - - Q_PRIVATE_SLOT( d, void slotInsertRows( const QModelIndex&, int, int) ) - Q_PRIVATE_SLOT( d, void slotRemoveRows( const QModelIndex&, int, int) ) - Q_PRIVATE_SLOT( d, void slotCollectionChanged() ) -}; - -} - -#endif diff --git a/akonadi/kmime/messagethreadingattribute.cpp b/akonadi/kmime/messagethreadingattribute.cpp deleted file mode 100644 index 3e733cecb..000000000 --- a/akonadi/kmime/messagethreadingattribute.cpp +++ /dev/null @@ -1,135 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "messagethreadingattribute.h" - -using namespace Akonadi; - -class Akonadi::MessageThreadingAttribute::Private -{ - public: - QList perfectParents; - QList unperfectParents; - QList subjectParents; -}; - -MessageThreadingAttribute::MessageThreadingAttribute() : - d( new Private ) -{ -} - -MessageThreadingAttribute::MessageThreadingAttribute(const MessageThreadingAttribute & other) : - Attribute( other ), - d( new Private( *(other.d) ) ) -{ -} - -MessageThreadingAttribute::~ MessageThreadingAttribute() -{ - delete d; -} - -QByteArray MessageThreadingAttribute::type() const -{ - return "MESSAGETHREADING"; -} - -MessageThreadingAttribute * MessageThreadingAttribute::clone() const -{ - return new MessageThreadingAttribute( *this ); -} - -QByteArray MessageThreadingAttribute::serialized() const -{ - QByteArray rv; - foreach ( const Item::Id id, d->perfectParents ) - rv += QByteArray::number( id ) + ','; - if ( !d->perfectParents.isEmpty() ) - rv[rv.size() - 1] = ';'; - else - rv += ';'; - foreach ( const Item::Id id, d->unperfectParents ) - rv += QByteArray::number( id ) + ','; - if ( !d->unperfectParents.isEmpty() ) - rv[rv.size() - 1] = ';'; - else - rv += ';'; - foreach ( const Item::Id id, d->subjectParents ) - rv += QByteArray::number( id ) + ','; - if ( !d->perfectParents.isEmpty() ) - rv.chop( 1 ); - - return rv; -} - -static void parseIdList( const QByteArray &data, QList &result ) -{ - bool ok = false; - foreach( const QByteArray &s, data.split( ',' ) ) { - Item::Id id = s.toLongLong( &ok ); - if( !ok ) - continue; - result << id; - } -} - -void MessageThreadingAttribute::deserialize(const QByteArray & data) -{ - d->perfectParents.clear(); - d->unperfectParents.clear(); - d->subjectParents.clear(); - - QList lists = data.split( ';' ); - if ( lists.size() != 3 ) - return; - - parseIdList( lists[0], d->perfectParents ); - parseIdList( lists[1], d->unperfectParents ); - parseIdList( lists[2], d->subjectParents ); -} - -QList< Item::Id > MessageThreadingAttribute::perfectParents() const -{ - return d->perfectParents; -} - -void MessageThreadingAttribute::setPerfectParents(const QList< Item::Id > & parents) -{ - d->perfectParents = parents; -} - -QList< Item::Id > MessageThreadingAttribute::unperfectParents() const -{ - return d->unperfectParents; -} - -void MessageThreadingAttribute::setUnperfectParents(const QList< Item::Id > & parents) -{ - d->unperfectParents = parents; -} - -QList< Item::Id > MessageThreadingAttribute::subjectParents() const -{ - return d->subjectParents; -} - -void MessageThreadingAttribute::setSubjectParents(const QList< Item::Id > & parents) -{ - d->subjectParents = parents; -} diff --git a/akonadi/kmime/messagethreadingattribute.h b/akonadi/kmime/messagethreadingattribute.h deleted file mode 100644 index 9e7e328b7..000000000 --- a/akonadi/kmime/messagethreadingattribute.h +++ /dev/null @@ -1,93 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_MESSAGETHREADINGATTRIBUTE_H -#define AKONADI_MESSAGETHREADINGATTRIBUTE_H - -#include "akonadi-kmime_export.h" -#include -#include - -namespace Akonadi { - -/** - Message threading information. Used eg. by MessageThreaderProxyModel -*/ -class AKONADI_KMIME_EXPORT MessageThreadingAttribute : public Attribute -{ - public: - /** - Creates an empty threading attribute. - */ - MessageThreadingAttribute(); - - /** - Copy constructor. - */ - MessageThreadingAttribute( const MessageThreadingAttribute &other ); - - /** - Destructor. - */ - ~MessageThreadingAttribute(); - - /** - Returns the list of perfect parent message ids. - */ - QList perfectParents() const; - - /** - Sets the list of perfect parent message ids. - */ - void setPerfectParents( const QList &parents ); - - /** - Returns the list of non-perfect parent message ids. - */ - QList unperfectParents() const; - - /** - Sets the list of non-perfect parent message ids. - */ - void setUnperfectParents( const QList &parents ); - - /** - Returns the list of possible parent message ids based on analyzing the subject. - */ - QList subjectParents() const; - - /** - Sets the list of possible parent message ids based on analyzing the subject. - */ - void setSubjectParents( const QList &parents ); - - // reimpl. - QByteArray type() const; - MessageThreadingAttribute* clone() const; - QByteArray serialized() const; - void deserialize( const QByteArray &data ); - - private: - class Private; - Private * const d; -}; - -} - -#endif diff --git a/akonadi/monitor.cpp b/akonadi/monitor.cpp deleted file mode 100644 index 6ca50c35c..000000000 --- a/akonadi/monitor.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/* - Copyright (c) 2006 - 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "monitor.h" -#include "monitor_p.h" - -#include "itemfetchjob.h" -#include "notificationmessage_p.h" -#include "session.h" - -#include - -#include -#include - -#include -#include - -using namespace Akonadi; - -#define d d_ptr - -Monitor::Monitor( QObject *parent ) : - QObject( parent ), - d_ptr( new MonitorPrivate( this ) ) -{ - d_ptr->connectToNotificationManager(); -} - -//@cond PRIVATE -Monitor::Monitor(MonitorPrivate * d, QObject *parent) : - QObject( parent ), - d_ptr( d ) -{ -} -//@endcond - -Monitor::~Monitor() -{ - delete d; -} - -void Monitor::setCollectionMonitored( const Collection &collection, bool monitored ) -{ - if ( monitored ) - d->collections << collection; - else - d->collections.removeAll( collection ); -} - -void Monitor::setItemMonitored( const Item & item, bool monitored ) -{ - if ( monitored ) - d->items.insert( item.id() ); - else - d->items.remove( item.id() ); -} - -void Monitor::setResourceMonitored( const QByteArray & resource, bool monitored ) -{ - if ( monitored ) - d->resources.insert( resource ); - else - d->resources.remove( resource ); -} - -void Monitor::setMimeTypeMonitored( const QString & mimetype, bool monitored ) -{ - if ( monitored ) - d->mimetypes.insert( mimetype ); - else - d->mimetypes.remove( mimetype ); -} - -void Akonadi::Monitor::setAllMonitored( bool monitored ) -{ - d->monitorAll = monitored; -} - -void Monitor::ignoreSession(Session * session) -{ - d->sessions << session->sessionId(); -} - -void Monitor::fetchCollection(bool enable) -{ - d->fetchCollection = enable; -} - -void Monitor::fetchCollectionStatistics(bool enable) -{ - d->fetchCollectionStatistics = enable; -} - -void Monitor::setItemFetchScope( const ItemFetchScope &fetchScope ) -{ - d->mItemFetchScope = fetchScope; -} - -ItemFetchScope &Monitor::itemFetchScope() -{ - return d->mItemFetchScope; -} - -#undef d - -#include "monitor.moc" diff --git a/akonadi/monitor.h b/akonadi/monitor.h deleted file mode 100644 index a36c82239..000000000 --- a/akonadi/monitor.h +++ /dev/null @@ -1,240 +0,0 @@ -/* - Copyright (c) 2006 - 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_MONITOR_H -#define AKONADI_MONITOR_H - -#include - -#include - -namespace Akonadi { - -class CollectionStatistics; -class Item; -class ItemFetchScope; -class MonitorPrivate; -class Session; - -/** - * @short Monitors an item or collection for changes. - * - * The Monitor emits signals if some of these objects are changed or - * removed or new ones are added to the Akonadi storage. - * - * Optionally, the changed objects can be fetched automatically from the server. - * To enable this, see fetchCollection(), fetchItemMetaData(), fetchItemData(). - * - * @todo: distinguish between monitoring collection properties and collection content. - * @todo: special case for collection content counts changed - * - * @author Volker Krause - */ -class AKONADI_EXPORT Monitor : public QObject -{ - Q_OBJECT - - public: - /** - * Creates a new monitor. - * - * @param parent The parent object. - */ - explicit Monitor( QObject *parent = 0 ); - - /** - * Destroys the monitor. - */ - virtual ~Monitor(); - - /** - * Sets whether the specified collection shall be monitored for changes. - * - * @param collection The collection to monitor. - * If this collection is Collection::root(), all collections - * in the Akonadi storage will be monitored. - */ - void setCollectionMonitored( const Collection &collection, bool monitored = true ); - - /** - * Sets whether the specified item shall be monitored for changes. - * - * @param item The item to monitor. - */ - void setItemMonitored( const Item &item, bool monitored = true ); - - /** - * Sets whether the specified resource shall be monitored for changes. - * - * @param resource The resource identifier. - */ - void setResourceMonitored( const QByteArray &resource, bool monitored = true ); - - /** - * Sets whether objects of the specified mime type shall be monitored for changes. - * - * @param mimetype The mime type to monitor. - */ - void setMimeTypeMonitored( const QString &mimetype, bool monitored = true ); - - /** - * Sets whether all items shall be monitored. - */ - void setAllMonitored( bool monitored = true ); - - /** - * Ignores all change notifications caused by the given session. - * - * @param session The session you want to ignore. - */ - void ignoreSession( Session *session ); - - /** - * Enables automatic fetching of changed collections from the Akonadi storage. - * - * @param enable @c true enables automatic fetching, @c false disables automatic fetching. - */ - void fetchCollection( bool enable ); - - /** - * Enables automatic fetching of changed collection statistics information from - * the Akonadi storage. - * - * @param enable @c true to enables automatic fetching, @c false disables automatic fetching. - */ - void fetchCollectionStatistics( bool enable ); - - /** - * Sets the item fetch scope. - * - * Controls how much of an item's data is fetched from the server, e.g. - * whether to fetch the full item payload or only meta data. - * - * @param fetchScope The new scope for item fetch operations. - * - * @see itemFetchScope() - */ - void setItemFetchScope( const ItemFetchScope &fetchScope ); - - /** - * Returns the item fetch scope. - * - * Since this returns a reference it can be used to conveniently modify the - * current scope in-place, i.e. by calling a method on the returned reference - * without storing it in a local variable. See the ItemFetchScope documentation - * for an example. - * - * @return a reference to the current item fetch scope - * - * @see setItemFetchScope() for replacing the current item fetch scope - */ - ItemFetchScope &itemFetchScope(); - - Q_SIGNALS: - /** - * This signal is emitted if a monitored item has changed, e.g. item parts have been modified. - * - * @param item The changed item. - * @param partIdentifiers The identifiers of the item parts that has been changed. - */ - void itemChanged( const Akonadi::Item &item, const QSet &partIdentifiers ); - - /** - * This signal is emitted if a monitored item has been moved between two collections - * - * @param item The moved item. - * @param collectionSource The collection the item has been moved from. - * @param collectionDestination The collection the item has been moved to. - */ - void itemMoved( const Akonadi::Item &item, const Akonadi::Collection &collectionSource, - const Akonadi::Collection &collectionDestination ); - - /** - * This signal is emitted if an item has been added to a monitored collection in the Akonadi storage. - * - * @param item The new item. - * @param collection The collection the item has been added to. - */ - void itemAdded( const Akonadi::Item &item, const Akonadi::Collection &collection ); - - /** - * This signal is emitted if - * - a monitored item has been removed from the Akonadi storage - * or - * - a item has been removed from a monitored collection. - * - * @param item The removed item. - */ - void itemRemoved( const Akonadi::Item &item ); - - /** - * This signal is emitted if a new collection has been added to a monitored collection in the Akonadi storage. - * - * @param collection The new collection. - * @param parent The parent collection. - */ - void collectionAdded( const Akonadi::Collection &collection, const Akonadi::Collection &parent ); - - /** - * This signal is emitted if a monitored collection has been changed (properties or content) - * or has been reparented. - * - * @param collection The changed collection. - */ - void collectionChanged( const Akonadi::Collection &collection ); - - /** - * This signal is emitted if a monitored collection has been removed from the Akonadi storage. - * - * @param collection The removed collection. - */ - void collectionRemoved( const Akonadi::Collection &collection ); - - /** - * This signal is emitted if the statistics information of a monitored collection - * has changed. - * - * @param id The collection identifier of the changed collection. - * @param statistics The updated collection statistics, invalid if automatic - * fetching of statistics changes is disabled. - */ - void collectionStatisticsChanged( Akonadi::Collection::Id id, - const Akonadi::CollectionStatistics &statistics ); - - protected: - //@cond PRIVATE - MonitorPrivate *d_ptr; - explicit Monitor( MonitorPrivate *d, QObject *parent = 0 ); - //@endcond - - private: - Q_DECLARE_PRIVATE( Monitor ) - - //@cond PRIVATE - Q_PRIVATE_SLOT( d_ptr, void slotStatisticsChangedFinished( KJob* ) ) - Q_PRIVATE_SLOT( d_ptr, void slotFlushRecentlyChangedCollections() ) - Q_PRIVATE_SLOT( d_ptr, void slotNotify( const Akonadi::NotificationMessage::List& ) ) - Q_PRIVATE_SLOT( d_ptr, void slotItemJobFinished( KJob* ) ) - Q_PRIVATE_SLOT( d_ptr, void slotCollectionJobFinished( KJob* ) ) - //@endcond -}; - -} - -#endif diff --git a/akonadi/monitor_p.cpp b/akonadi/monitor_p.cpp deleted file mode 100644 index 73c5ced7e..000000000 --- a/akonadi/monitor_p.cpp +++ /dev/null @@ -1,354 +0,0 @@ -/* - Copyright (c) 2007 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -// @cond PRIVATE - -#include "monitor_p.h" - -#include "collectionfetchjob.h" -#include "collectionstatistics.h" -#include "itemfetchjob.h" -#include "notificationmessage_p.h" -#include "session.h" - -#include - -using namespace Akonadi; - -MonitorPrivate::MonitorPrivate(Monitor * parent) : - q_ptr( parent ), - nm( 0 ), - monitorAll( false ), - fetchCollection( false ), - fetchCollectionStatistics( false ) -{ -} - -bool MonitorPrivate::connectToNotificationManager() -{ - NotificationMessage::registerDBusTypes(); - - if ( !nm ) - nm = new org::freedesktop::Akonadi::NotificationManager( QLatin1String( "org.freedesktop.Akonadi" ), - QLatin1String( "/notifications" ), - QDBusConnection::sessionBus(), q_ptr ); - else - return true; - - if ( !nm ) { - kWarning( 5250 ) << "Unable to connect to notification manager"; - } else { - QObject::connect( nm, SIGNAL(notify(Akonadi::NotificationMessage::List)), - q_ptr, SLOT(slotNotify(Akonadi::NotificationMessage::List)) ); - return true; - } - return false; -} - -bool MonitorPrivate::acceptNotification(const NotificationMessage & msg) -{ - if ( isSessionIgnored( msg.sessionId() ) ) - return false; - switch ( msg.type() ) { - case NotificationMessage::InvalidType: - kWarning( 5250 ) << "Received invalid change notification!"; - return false; - case NotificationMessage::Item: - return isItemMonitored( msg.uid(), msg.parentCollection(), msg.parentDestCollection(), msg.mimeType(), msg.resource() ) - || isCollectionMonitored( msg.parentCollection(), msg.resource() ) - || isCollectionMonitored( msg.parentDestCollection(), msg.resource() ); - case NotificationMessage::Collection: - return isCollectionMonitored( msg.uid(), msg.resource() ); - } - Q_ASSERT( false ); - return false; -} - -bool MonitorPrivate::processNotification(const NotificationMessage & msg) -{ - if ( !acceptNotification( msg ) ) - return false; - - if ( msg.type() == NotificationMessage::Item ) { - notifyCollectionStatisticsWatchers( msg.parentCollection(), msg.resource() ); - if ( !mItemFetchScope.isEmpty() && - ( msg.operation() == NotificationMessage::Add || msg.operation() == NotificationMessage::Move ) ) { - Item item( msg.uid() ); - item.setRemoteId( msg.remoteId() ); - - ItemCollectionFetchJob *job = new ItemCollectionFetchJob( item, msg.parentCollection(), q_ptr ); - job->setFetchScope( mItemFetchScope ); - pendingJobs.insert( job, msg ); - QObject::connect( job, SIGNAL(result(KJob*)), q_ptr, SLOT(slotItemJobFinished(KJob*)) ); - return true; - } - if ( !mItemFetchScope.isEmpty() && msg.operation() == NotificationMessage::Modify ) { - Item item( msg.uid() ); - item.setRemoteId( msg.remoteId() ); - ItemFetchJob *job = new ItemFetchJob( item, q_ptr ); - job->setFetchScope( mItemFetchScope ); - pendingJobs.insert( job, msg ); - QObject::connect( job, SIGNAL(result(KJob*)), q_ptr, SLOT(slotItemJobFinished(KJob*)) ); - return true; - } - emitItemNotification( msg ); - return true; - - } else if ( msg.type() == NotificationMessage::Collection ) { - if ( msg.operation() != NotificationMessage::Remove && fetchCollection ) { - Collection::List list; - list << Collection( msg.uid() ); - if ( msg.operation() == NotificationMessage::Add ) - list << Collection( msg.parentCollection() ); - CollectionFetchJob *job = new CollectionFetchJob( list, q_ptr ); - pendingJobs.insert( job, msg ); - QObject::connect( job, SIGNAL(result(KJob*)), q_ptr, SLOT(slotCollectionJobFinished(KJob*)) ); - return true; - } - if ( msg.operation() == NotificationMessage::Remove ) { - // no need for statistics updates anymore - recentlyChangedCollections.remove( msg.uid() ); - } - emitCollectionNotification( msg ); - return true; - - } else { - kWarning( 5250 ) << "Received unknown change notification!"; - } - return false; -} - -void MonitorPrivate::sessionDestroyed( QObject * object ) -{ - Session* session = qobject_cast( object ); - if ( session ) - sessions.removeAll( session->sessionId() ); -} - -void MonitorPrivate::slotStatisticsChangedFinished( KJob* job ) -{ - if ( job->error() ) { - kWarning( 5250 ) << "Error on fetching collection statistics: " << job->errorText(); - } else { - CollectionStatisticsJob *statisticsJob = static_cast( job ); - emit q_ptr->collectionStatisticsChanged( statisticsJob->collection().id(), - statisticsJob->statistics() ); - } -} - -void MonitorPrivate::slotFlushRecentlyChangedCollections() -{ - foreach( Collection::Id collection, recentlyChangedCollections ) { - if ( fetchCollectionStatistics ) { - fetchStatistics( collection ); - } else { - static const CollectionStatistics dummyStatistics; - emit q_ptr->collectionStatisticsChanged( collection, dummyStatistics ); - } - } - recentlyChangedCollections.clear(); -} - -void MonitorPrivate::slotNotify( const NotificationMessage::List &msgs ) -{ - foreach ( const NotificationMessage &msg, msgs ) - processNotification( msg ); -} - -void MonitorPrivate::emitItemNotification( const NotificationMessage &msg, const Item &item, - const Collection &collection, const Collection &collectionDest ) -{ - Q_ASSERT( msg.type() == NotificationMessage::Item ); - Collection col = collection; - Collection colDest = collectionDest; - if ( !col.isValid() ) { - col = Collection( msg.parentCollection() ); - col.setResource( QString::fromUtf8( msg.resource() ) ); - } - if ( !colDest.isValid() ) { - colDest = Collection( msg.parentDestCollection() ); - // FIXME setResource here required ? - } - Item it = item; - if ( !it.isValid() ) { - it = Item( msg.uid() ); - it.setRemoteId( msg.remoteId() ); - it.setMimeType( msg.mimeType() ); - } - switch ( msg.operation() ) { - case NotificationMessage::Add: - emit q_ptr->itemAdded( it, col ); - break; - case NotificationMessage::Modify: - emit q_ptr->itemChanged( it, msg.itemParts() ); - break; - case NotificationMessage::Move: - emit q_ptr->itemMoved( it, col, colDest ); - break; - case NotificationMessage::Remove: - emit q_ptr->itemRemoved( it ); - break; - default: - break; - } -} - -void MonitorPrivate::emitCollectionNotification( const NotificationMessage &msg, const Collection &col, - const Collection &par ) -{ - Q_ASSERT( msg.type() == NotificationMessage::Collection ); - Collection collection = col; - if ( !collection.isValid() ) { - collection = Collection( msg.uid() ); - collection.setParent( msg.parentCollection() ); - collection.setResource( QString::fromUtf8( msg.resource() ) ); - collection.setRemoteId( msg.remoteId() ); - } - Collection parent = par; - if ( !parent.isValid() ) - parent = Collection( msg.parentCollection() ); - switch ( msg.operation() ) { - case NotificationMessage::Add: - emit q_ptr->collectionAdded( collection, parent ); - break; - case NotificationMessage::Modify: - emit q_ptr->collectionChanged( collection ); - break; - case NotificationMessage::Remove: - emit q_ptr->collectionRemoved( collection ); - break; - default: - Q_ASSERT_X( false, "MonitorPrivate::emitCollectionNotification", "Invalid enum value" ); - } -} - -void MonitorPrivate::slotItemJobFinished( KJob* job ) -{ - if ( !pendingJobs.contains( job ) ) { - kWarning( 5250 ) << "Unknown job - wtf is going on here?"; - return; - } - NotificationMessage msg = pendingJobs.take( job ); - if ( job->error() ) { - kWarning( 5250 ) << "Error on fetching item:" << job->errorText(); - } else { - Item item; - Collection col; - ItemFetchJob *fetchJob = qobject_cast( job ); - if ( fetchJob && fetchJob->items().count() > 0 ) - item = fetchJob->items().first(); - ItemCollectionFetchJob *cfjob = qobject_cast( job ); - if ( cfjob ) { - item = cfjob->item(); - col = cfjob->collection(); - } - emitItemNotification( msg, item, col ); - } -} - -void MonitorPrivate::slotCollectionJobFinished( KJob* job ) -{ - if ( !pendingJobs.contains( job ) ) { - kWarning( 5250 ) << "Unknown job - wtf is going on here?"; - return; - } - NotificationMessage msg = pendingJobs.take( job ); - if ( job->error() ) { - kWarning( 5250 ) << "Error on fetching collection:" << job->errorText(); - } else { - Collection col, parent; - CollectionFetchJob *listJob = qobject_cast( job ); - if ( listJob && listJob->collections().count() > 0 ) - col = listJob->collections().first(); - if ( listJob && listJob->collections().count() > 1 && msg.operation() == NotificationMessage::Add ) { - parent = listJob->collections().at( 1 ); - if ( col.id() != msg.uid() ) - qSwap( col, parent ); - } - emitCollectionNotification( msg, col, parent ); - } -} - - -ItemCollectionFetchJob::ItemCollectionFetchJob( const Item &item, Collection::Id collectionId, QObject *parent ) - : Job( parent ), - mReferenceItem( item ), mCollectionId( collectionId ) -{ -} - -ItemCollectionFetchJob::~ItemCollectionFetchJob() -{ -} - -Item ItemCollectionFetchJob::item() const -{ - return mItem; -} - -Collection ItemCollectionFetchJob::collection() const -{ - return mCollection; -} - -void ItemCollectionFetchJob::setFetchScope( const ItemFetchScope &fetchScope ) -{ - mFetchScope = fetchScope; -} - -void ItemCollectionFetchJob::doStart() -{ - CollectionFetchJob *listJob = new CollectionFetchJob( Collection( mCollectionId ), CollectionFetchJob::Base, this ); - connect( listJob, SIGNAL( result( KJob* ) ), SLOT( collectionJobDone( KJob* ) ) ); - addSubjob( listJob ); - - ItemFetchJob *fetchJob = new ItemFetchJob( mReferenceItem, this ); - fetchJob->setFetchScope( mFetchScope ); - connect( fetchJob, SIGNAL( result( KJob* ) ), SLOT( itemJobDone( KJob* ) ) ); - addSubjob( fetchJob ); -} - -void ItemCollectionFetchJob::collectionJobDone( KJob* job ) -{ - if ( !job->error() ) { - CollectionFetchJob *listJob = qobject_cast( job ); - if ( listJob->collections().isEmpty() ) { - setError( 1 ); - setErrorText( QLatin1String( "No collection found" ) ); - } else - mCollection = listJob->collections().first(); - } -} - -void ItemCollectionFetchJob::itemJobDone( KJob* job ) -{ - if ( !job->error() ) { - ItemFetchJob *fetchJob = qobject_cast( job ); - if ( fetchJob->items().isEmpty() ) { - setError( 2 ); - setErrorText( QLatin1String( "No item found" ) ); - } else - mItem = fetchJob->items().first(); - - emitResult(); - } -} - -// @endcond - -#include "monitor_p.moc" diff --git a/akonadi/monitor_p.h b/akonadi/monitor_p.h deleted file mode 100644 index a15408c5a..000000000 --- a/akonadi/monitor_p.h +++ /dev/null @@ -1,188 +0,0 @@ -/* - Copyright (c) 2007 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_MONITOR_P_H -#define AKONADI_MONITOR_P_H - -#include "monitor.h" -#include "collection.h" -#include "collectionstatisticsjob.h" -#include "item.h" -#include "itemfetchscope.h" -#include "job.h" -#include -#include "notificationmanagerinterface.h" - -#include - -#include -#include - -namespace Akonadi { - -class Monitor; - -/** - * @internal - */ -class MonitorPrivate -{ - public: - MonitorPrivate( Monitor *parent ); - virtual ~MonitorPrivate() {} - - Monitor *q_ptr; - Q_DECLARE_PUBLIC( Monitor ) - org::freedesktop::Akonadi::NotificationManager *nm; - Collection::List collections; - QSet resources; - QSet items; - QSet mimetypes; - bool monitorAll; - QList sessions; - ItemFetchScope mItemFetchScope; - QHash pendingJobs; - - bool isCollectionMonitored( Collection::Id collection, const QByteArray &resource ) const - { - if ( monitorAll || isCollectionMonitored( collection ) || resources.contains( resource ) ) - return true; - return false; - } - - bool isItemMonitored( Item::Id item, Collection::Id collection, Collection::Id collectionDest, - const QString &mimetype, const QByteArray &resource ) const - { - if ( monitorAll || isCollectionMonitored( collection ) || - isCollectionMonitored( collectionDest ) ||items.contains( item ) || - resources.contains( resource ) || isMimeTypeMonitored( mimetype ) ) - return true; - return false; - } - - bool isSessionIgnored( const QByteArray &sessionId ) const - { - return sessions.contains( sessionId ); - } - - bool connectToNotificationManager(); - bool acceptNotification( const NotificationMessage &msg ); - bool processNotification( const NotificationMessage &msg ); - - // private slots - void sessionDestroyed( QObject* ); - void slotStatisticsChangedFinished( KJob* ); - void slotFlushRecentlyChangedCollections(); - - virtual void slotNotify( const NotificationMessage::List &msgs ); - void slotItemJobFinished( KJob* job ); - void slotCollectionJobFinished( KJob *job ); - - void emitItemNotification( const NotificationMessage &msg, const Item &item = Item(), - const Collection &collection = Collection(), const Collection &collectionDest = Collection() ); - void emitCollectionNotification( const NotificationMessage &msg, const Collection &col = Collection(), - const Collection &par = Collection() ); - - bool fetchCollection; - bool fetchCollectionStatistics; - - private: - // collections that need a statistics update - QSet recentlyChangedCollections; - - bool isCollectionMonitored( Collection::Id collection ) const - { - if ( collections.contains( Collection( collection ) ) ) - return true; - if ( collections.contains( Collection::root() ) ) - return true; - return false; - } - - bool isMimeTypeMonitored( const QString& mimetype ) const - { - if ( mimetypes.contains( mimetype ) ) - return true; - - KMimeType::Ptr mimeType = KMimeType::mimeType( mimetype, KMimeType::ResolveAliases ); - if ( mimeType.isNull() ) - return false; - - foreach ( const QString &mt, mimetypes ) { - if ( mimeType->is( mt ) ) - return true; - } - - return false; - } - - void fetchStatistics( Collection::Id colId ) - { - CollectionStatisticsJob *job = new CollectionStatisticsJob( Collection( colId ), q_ptr ); - QObject::connect( job, SIGNAL(result(KJob*)), q_ptr, SLOT(slotStatisticsChangedFinished(KJob*)) ); - } - - void notifyCollectionStatisticsWatchers( Collection::Id collection, const QByteArray &resource ) - { - if ( isCollectionMonitored( collection, resource ) ) { - if (recentlyChangedCollections.empty() ) - QTimer::singleShot( 500, q_ptr, SLOT(slotFlushRecentlyChangedCollections()) ); - recentlyChangedCollections.insert( collection ); - } - } -}; - - -/** - * @internal - * - * A job which fetches a job and a collection. - */ -class AKONADI_EXPORT ItemCollectionFetchJob : public Job -{ - Q_OBJECT - - public: - explicit ItemCollectionFetchJob( const Item &item, Collection::Id collectionId, QObject *parent = 0 ); - ~ItemCollectionFetchJob(); - - Item item() const; - Collection collection() const; - - void setFetchScope( const ItemFetchScope &fetchScope ); - - protected: - virtual void doStart(); - - private Q_SLOTS: - void collectionJobDone( KJob* job ); - void itemJobDone( KJob* job ); - - private: - Item mReferenceItem; - Collection::Id mCollectionId; - - Item mItem; - Collection mCollection; - ItemFetchScope mFetchScope; -}; - -} - -#endif diff --git a/akonadi/org.freedesktop.Akonadi.Agent.Control.xml b/akonadi/org.freedesktop.Akonadi.Agent.Control.xml deleted file mode 100644 index fc4472ee5..000000000 --- a/akonadi/org.freedesktop.Akonadi.Agent.Control.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - diff --git a/akonadi/pastehelper.cpp b/akonadi/pastehelper.cpp deleted file mode 100644 index 36ce8044e..000000000 --- a/akonadi/pastehelper.cpp +++ /dev/null @@ -1,110 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "pastehelper.h" - -#include "collectioncopyjob.h" -#include "collectionmodifyjob.h" -#include "item.h" -#include "itemcreatejob.h" -#include "itemcopyjob.h" -#include "itemmodifyjob.h" -#include "itemmovejob.h" -#include "transactionsequence.h" - -#include -#include - -#include -#include -#include - -using namespace Akonadi; - -bool PasteHelper::canPaste(const QMimeData * mimeData, const Collection & collection) -{ - if ( !mimeData || !collection.isValid() ) - return false; - - if ( KUrl::List::canDecode( mimeData ) ) - return true; - - foreach ( const QString &format, mimeData->formats() ) - if ( collection.contentMimeTypes().contains( format ) ) - return true; - - return false; -} - -KJob* PasteHelper::paste(const QMimeData * mimeData, const Collection & collection, bool copy) -{ - if ( !canPaste( mimeData, collection ) ) - return 0; - - // we try to drop data not coming with the akonadi:// url - // find a type the target collection supports - foreach ( const QString &type, mimeData->formats() ) { - if ( !collection.contentMimeTypes().contains( type ) ) - continue; - - QByteArray item = mimeData->data( type ); - // HACK for some unknown reason the data is sometimes 0-terminated... - if ( !item.isEmpty() && item.at( item.size() - 1 ) == 0 ) - item.resize( item.size() - 1 ); - - Item it; - it.setMimeType( type ); - it.setPayloadFromData( item ); - - ItemCreateJob *job = new ItemCreateJob( it, collection ); - return job; - } - - if ( !KUrl::List::canDecode( mimeData ) ) - return 0; - - // data contains an url list - TransactionSequence *transaction = new TransactionSequence(); - KUrl::List urls = KUrl::List::fromMimeData( mimeData ); - foreach ( const KUrl &url, urls ) { - if ( Collection::fromUrl( url ).isValid() ) { - Collection col = Collection::fromUrl( url ); - if ( !copy ) { - col.setParent( collection ); - CollectionModifyJob *job = new CollectionModifyJob( col, transaction ); - } else { - new CollectionCopyJob( col, collection, transaction ); - } - } else if ( Item::fromUrl( url ).isValid() ) { - // TODO Extract mimetype from url and check if collection accepts it - const Item item = Item::fromUrl( url ); - if ( !copy ) { - new ItemMoveJob( item, collection, transaction ); - } else { - new ItemCopyJob( item, collection, transaction ); - } - } else { - // non-akonadi URL - // TODO - kDebug() << "Implement me!"; - } - } - return transaction; -} - diff --git a/akonadi/pastehelper.h b/akonadi/pastehelper.h deleted file mode 100644 index 1fad4051a..000000000 --- a/akonadi/pastehelper.h +++ /dev/null @@ -1,61 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_PASTEHELPER_H -#define AKONADI_PASTEHELPER_H - -#include - -#include - -class KJob; -class QMimeData; - -namespace Akonadi { - -/** - @internal - - Helper methods for pasting/droping content into a collection. - - @todo Use in item/collection models as well for dnd -*/ -namespace PasteHelper -{ - /** - Check whether the given mime data can be pasted into the given collection. - @param mimeData The pasted/dropped data. - @param collection The collection to paste/drop into. - */ - bool canPaste( const QMimeData* mimeData, const Collection &collection ); - - /** - Paste/drop the given mime data into the given collection. - @param mimeData The pasted/dropped data. - @param collection The target collection. - @param copy Indicate whether this is a copy or a move. - @returns The job performing the paste, 0 if there is nothing to paste. - */ - KJob* paste( const QMimeData* mimeData, const Collection &collection, bool copy = true ); -} - - -} - -#endif diff --git a/akonadi/pluginloader.cpp b/akonadi/pluginloader.cpp deleted file mode 100644 index 018d95335..000000000 --- a/akonadi/pluginloader.cpp +++ /dev/null @@ -1,157 +0,0 @@ -/* -*- c++ -*- - Copyright (c) 2008 Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "pluginloader.h" - -#include -#include -#include -#include -#include -#include - -#include -#include - -using namespace Akonadi; - -PluginMetaData::PluginMetaData() -{ -} - -PluginMetaData::PluginMetaData( const QString & lib, const QString & name, const QString & comment ) - : library( lib ), nameLabel( name ), - descriptionLabel( comment ), loaded( false ) -{ -} - - -PluginLoader* PluginLoader::mSelf = 0; - -PluginLoader::PluginLoader() -{ - scan(); -} - -PluginLoader::~PluginLoader() -{ - qDeleteAll( mPluginLoaders ); - mPluginLoaders.clear(); -} - -PluginLoader* PluginLoader::self() -{ - if ( !mSelf ) - mSelf = new PluginLoader(); - - return mSelf; -} - -QStringList PluginLoader::types() const -{ - return mPluginInfos.keys(); -} - -QObject* PluginLoader::createForName( const QString &type ) -{ - if ( !mPluginInfos.contains( type ) ) { - kWarning( 5300 ) << "plugin type \"" << type << "\" is unknown to the plugin loader." << endl; - return 0; - } - - PluginMetaData &info = mPluginInfos[ type ]; - if ( !info.loaded ) { - const QString path = KLibLoader::findLibrary( info.library ); - if ( path.isEmpty() ) { - kWarning( 5300 ) << "unable to find library for plugin type \"" << type << "\"." << endl; - return 0; - } - - mPluginLoaders.insert( type, new QPluginLoader( path ) ); - info.loaded = true; - } - - QPluginLoader *loader = mPluginLoaders[ type ]; - - QObject *object = loader->instance(); - if ( !object ) { - kWarning( 5300 ) << "unable to load plugin for plugin type \"" << type << "\"." << endl; - return 0; - } - - return object; -} - -PluginMetaData PluginLoader::infoForName( const QString & type ) const -{ - if ( !mPluginInfos.contains( type ) ) - return PluginMetaData(); - - return mPluginInfos.value( type ); -} - -void PluginLoader::scan() -{ - const QStringList list = KGlobal::dirs()->findAllResources( "data", QLatin1String( "akonadi/plugins/serializer/*.desktop" ), - KStandardDirs::Recursive | KStandardDirs::NoDuplicates ); - for ( int i = 0; i < list.count(); ++i ) { - const QString entry = list.at( i ); - - KConfig config( entry, KConfig::SimpleConfig ); - if ( config.hasGroup( "Misc" ) && config.hasGroup( "Plugin" ) ) { - KConfigGroup group( &config, "Plugin" ); - - const QString type = group.readEntry( "Type" ).toLower(); - if ( type.isEmpty() ) { - kWarning( 5300 ) << "missing or empty [Plugin]Type value in \"" << entry << "\" - skipping" << endl; - continue; - } - - const QString library = group.readEntry( "X-KDE-Library" ); - if ( library.isEmpty() ) { - kWarning( 5300 ) << "missing or empty [Plugin]X-KDE-Library value in \"" << entry << "\" - skipping" << endl; - continue; - } - - KConfigGroup group2( &config, "Misc" ); - - QString name = group2.readEntry( "Name" ); - if ( name.isEmpty() ) { - kWarning( 5300 ) << "missing or empty [Misc]Name value in \"" << entry << "\" - inserting default name" << endl; - name = i18n("Unnamed plugin"); - } - - QString comment = group2.readEntry( "Comment" ); - if ( comment.isEmpty() ) { - kWarning( 5300 ) << "missing or empty [Misc]Comment value in \"" << entry << "\" - inserting default name" << endl; - comment = i18n("No description available"); - } - - if ( type.contains( QLatin1Char( ',' ) ) ) { - const QStringList subTypes = type.split( QLatin1Char( ',' ), QString::SkipEmptyParts ); - for ( int j = 0; j < subTypes.count(); ++j ) - mPluginInfos.insert( subTypes.at( j ), PluginMetaData( library, name, comment ) ); - } else { - mPluginInfos.insert( type, PluginMetaData( library, name, comment ) ); - } - } else { - kWarning( 5300 ) << "Desktop file \"" << entry << "\" doesn't seem to describe a plugin " << "(misses Misc and/or Plugin group)" << endl; - } - } -} diff --git a/akonadi/pluginloader.h b/akonadi/pluginloader.h deleted file mode 100644 index c2552e22a..000000000 --- a/akonadi/pluginloader.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- c++ -*- - Copyright (c) 2008 Tobias Koenig - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef AKONADI_PLUGINLOADER_H -#define AKONADI_PLUGINLOADER_H - -#include "akonadiprivate_export.h" - -#include -#include - -class QPluginLoader; - -namespace Akonadi { - -class AKONADI_TESTS_EXPORT PluginMetaData -{ - public: - PluginMetaData(); - PluginMetaData( const QString & lib, const QString & name, const QString & comment ); - - QString library; - QString nameLabel; - QString descriptionLabel; - bool loaded; -}; - -class AKONADI_TESTS_EXPORT PluginLoader -{ - public: - ~PluginLoader(); - - static PluginLoader* self(); - - QStringList types() const; - - QObject* createForName( const QString &type ); - - PluginMetaData infoForName( const QString & type ) const; - - void scan(); - - private: - PluginLoader(); - - static PluginLoader *mSelf; - QHash mPluginLoaders; - QHash mPluginInfos; -}; - -} - -#endif diff --git a/akonadi/protocolhelper.cpp b/akonadi/protocolhelper.cpp deleted file mode 100644 index 81b6e60a4..000000000 --- a/akonadi/protocolhelper.cpp +++ /dev/null @@ -1,172 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "protocolhelper.h" - -#include "attributefactory.h" -#include "imapparser_p.h" - -#include - -#include - -using namespace Akonadi; - -int ProtocolHelper::parseCachePolicy(const QByteArray & data, CachePolicy & policy, int start) -{ - QVarLengthArray params; - int end = Akonadi::ImapParser::parseParenthesizedList( data, params, start ); - for ( int i = 0; i < params.count() - 1; i += 2 ) { - const QByteArray key = params[i]; - const QByteArray value = params[i + 1]; - - if ( key == "INHERIT" ) - policy.setInheritFromParent( value == "true" ); - else if ( key == "INTERVAL" ) - policy.setIntervalCheckTime( value.toInt() ); - else if ( key == "CACHETIMEOUT" ) - policy.setCacheTimeout( value.toInt() ); - else if ( key == "SYNCONDEMAND" ) - policy.setSyncOnDemand( value == "true" ); - else if ( key == "LOCALPARTS" ) { - QVarLengthArray tmp; - QStringList parts; - Akonadi::ImapParser::parseParenthesizedList( value, tmp ); - for ( int j=0; j attributes; - pos = ImapParser::parseParenthesizedList( data, attributes, pos ); - - for ( int i = 0; i < attributes.count() - 1; i += 2 ) { - const QByteArray key = attributes[i]; - const QByteArray value = attributes[i + 1]; - - if ( key == "NAME" ) { - collection.setName( QString::fromUtf8( value ) ); - } else if ( key == "REMOTEID" ) { - collection.setRemoteId( QString::fromUtf8( value ) ); - } else if ( key == "RESOURCE" ) { - collection.setResource( QString::fromUtf8( value ) ); - } else if ( key == "MIMETYPE" ) { - QVarLengthArray ct; - ImapParser::parseParenthesizedList( value, ct ); - QStringList ct2; - for ( int j = 0; j < ct.size(); j++ ) - ct2 << QString::fromLatin1( ct[j] ); - collection.setContentMimeTypes( ct2 ); - } else if ( key == "CACHEPOLICY" ) { - CachePolicy policy; - ProtocolHelper::parseCachePolicy( value, policy ); - collection.setCachePolicy( policy ); - } else { - Attribute* attr = AttributeFactory::createAttribute( key ); - Q_ASSERT( attr ); - attr->deserialize( value ); - collection.addAttribute( attr ); - } - } - - return pos; -} - -QByteArray ProtocolHelper::attributesToByteArray(const Entity & entity, bool ns ) -{ - QList l; - foreach ( const Attribute *attr, entity.attributes() ) { - l << encodePartIdentifier( ns ? PartAttribute : PartGlobal, attr->type() ); - l << ImapParser::quote( attr->serialized() ); - } - return ImapParser::join( l, " " ); -} - -QByteArray ProtocolHelper::encodePartIdentifier(PartNamespace ns, const QByteArray & label, int version ) -{ - const QByteArray versionString( version != 0 ? '[' + QByteArray::number( version ) + ']' : "" ); - switch ( ns ) { - case PartGlobal: - return label + versionString; - case PartPayload: - return "PLD:" + label + versionString; - case PartAttribute: - return "ATR:" + label + versionString; - default: - Q_ASSERT( false ); - } - return QByteArray(); -} - -QByteArray ProtocolHelper::decodePartIdentifier( const QByteArray &data, PartNamespace & ns ) -{ - if ( data.startsWith( "PLD:" ) ) { - ns = PartPayload; - return data.mid( 4 ); - } else if ( data.startsWith( "ATR:" ) ) { - ns = PartAttribute; - return data.mid( 4 ); - } else { - ns = PartGlobal; - return data; - } -} diff --git a/akonadi/protocolhelper.h b/akonadi/protocolhelper.h deleted file mode 100644 index 66c87e4b9..000000000 --- a/akonadi/protocolhelper.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_PROTOCOLHELPER_H -#define AKONADI_PROTOCOLHELPER_H - -#include -#include - -namespace Akonadi { - -/** - @internal - Helper methods for converting between libakonadi objects and their protocol - representation. - - @todo Add unit tests for this. - @todo Use exceptions for a useful error handling -*/ -class ProtocolHelper -{ - public: - /** Part namespaces. */ - enum PartNamespace { - PartGlobal, - PartPayload, - PartAttribute - }; - - /** - Parse a cache policy definition. - @param data The input data. - @param policy The parsed cache policy. - @param start Start of the data, ie. postion after the label. - @returns Position in data after the cache policy description. - */ - static int parseCachePolicy( const QByteArray &data, CachePolicy &policy, int start = 0 ); - - /** - Convert a cache policy object into its protocol representation. - */ - static QByteArray cachePolicyToByteArray( const CachePolicy &policy ); - - /** - Parse a collection description. - @param data The input data. - @param collection The parsed collection. - @param start Start of the data. - @returns Position in data after the collection description. - */ - static int parseCollection( const QByteArray &data, Collection &collection, int start = 0 ); - - /** - Convert attributes to their protocol representation. - */ - static QByteArray attributesToByteArray( const Entity &entity, bool ns = false ); - - /** - Encodes part label and namespace. - */ - static QByteArray encodePartIdentifier( PartNamespace ns, const QByteArray &label, int version = 0 ); - - /** - Decode part label and namespace. - */ - static QByteArray decodePartIdentifier( const QByteArray &data, PartNamespace &ns ); -}; - -} - -#endif diff --git a/akonadi/resourcebase.cpp b/akonadi/resourcebase.cpp deleted file mode 100644 index 7a6ebfcc8..000000000 --- a/akonadi/resourcebase.cpp +++ /dev/null @@ -1,506 +0,0 @@ -/* - Copyright (c) 2006 Till Adam - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "resourcebase.h" -#include "agentbase_p.h" - -#include "resourceadaptor.h" -#include "collectionsync.h" -#include "itemsync.h" -#include "resourcescheduler.h" -#include "tracerinterface.h" -#include "xdgbasedirs_p.h" - -#include "changerecorder.h" -#include "collectionfetchjob.h" -#include "collectionmodifyjob.h" -#include "itemfetchjob.h" -#include "itemfetchscope.h" -#include "itemmodifyjob.h" -#include "itemmodifyjob_p.h" -#include "session.h" - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -using namespace Akonadi; - -class Akonadi::ResourceBasePrivate : public AgentBasePrivate -{ - public: - ResourceBasePrivate( ResourceBase *parent ) - : AgentBasePrivate( parent ), - scheduler( 0 ), - mItemSyncer( 0 ) - { - mStatusMessage = defaultReadyMessage(); - } - - Q_DECLARE_PUBLIC( ResourceBase ) - - void delayedInit() - { - if ( !QDBusConnection::sessionBus().registerService( QLatin1String( "org.freedesktop.Akonadi.Resource." ) + mId ) ) - kFatal() << "Unable to register service at D-Bus: " << QDBusConnection::sessionBus().lastError().message(); - AgentBasePrivate::delayedInit(); - } - - virtual void changeProcessed() - { - mMonitor->changeProcessed(); - if ( !mMonitor->isEmpty() ) - scheduler->scheduleChangeReplay(); - scheduler->taskDone(); - } - - void slotDeliveryDone( KJob* job ); - - void slotCollectionSyncDone( KJob *job ); - void slotLocalListDone( KJob *job ); - void slotSynchronizeCollection( const Collection &col ); - void slotCollectionListDone( KJob *job ); - - void slotItemSyncDone( KJob *job ); - - void slotPercent( KJob* job, unsigned long percent ); - - QString mName; - - // synchronize states - Collection currentCollection; - - ResourceScheduler *scheduler; - ItemSync *mItemSyncer; -}; - -ResourceBase::ResourceBase( const QString & id ) - : AgentBase( new ResourceBasePrivate( this ), id ) -{ - Q_D( ResourceBase ); - - new ResourceAdaptor( this ); - - const QString name = d->mSettings->value( QLatin1String( "Resource/Name" ) ).toString(); - if ( !name.isEmpty() ) - d->mName = name; - - d->scheduler = new ResourceScheduler( this ); - - d->mMonitor->setChangeRecordingEnabled( true ); - connect( d->mMonitor, SIGNAL(changesAdded()), - d->scheduler, SLOT(scheduleChangeReplay()) ); - - d->mMonitor->setResourceMonitored( d->mId.toLatin1() ); - - connect( d->scheduler, SIGNAL(executeFullSync()), - SLOT(retrieveCollections()) ); - connect( d->scheduler, SIGNAL(executeCollectionTreeSync()), - SLOT(retrieveCollections()) ); - connect( d->scheduler, SIGNAL(executeCollectionSync(Akonadi::Collection)), - SLOT(slotSynchronizeCollection(Akonadi::Collection)) ); - connect( d->scheduler, SIGNAL(executeItemFetch(Akonadi::Item,QSet)), - SLOT(retrieveItem(Akonadi::Item,QSet)) ); - connect( d->scheduler, SIGNAL(executeChangeReplay()), - d->mMonitor, SLOT(replayNext()) ); - - d->scheduler->setOnline( d->mOnline ); - if ( !d->mMonitor->isEmpty() ) - d->scheduler->scheduleChangeReplay(); -} - -ResourceBase::~ResourceBase() -{ -} - -void ResourceBase::synchronize() -{ - d_func()->scheduler->scheduleFullSync(); -} - -void ResourceBase::setName( const QString &name ) -{ - Q_D( ResourceBase ); - if ( name == d->mName ) - return; - - // TODO: rename collection - d->mName = name; - - if ( d->mName.isEmpty() || d->mName == d->mId ) - d->mSettings->remove( QLatin1String( "Resource/Name" ) ); - else - d->mSettings->setValue( QLatin1String( "Resource/Name" ), d->mName ); - - d->mSettings->sync(); - - emit nameChanged( d->mName ); -} - -QString ResourceBase::name() const -{ - Q_D( const ResourceBase ); - if ( d->mName.isEmpty() ) - return d->mId; - else - return d->mName; -} - -static char* sAppName = 0; - -QString ResourceBase::parseArguments( int argc, char **argv ) -{ - QString identifier; - if ( argc < 3 ) { - kDebug( 5250 ) << "Not enough arguments passed..."; - exit( 1 ); - } - - for ( int i = 1; i < argc - 1; ++i ) { - if ( QLatin1String( argv[ i ] ) == QLatin1String( "--identifier" ) ) - identifier = QLatin1String( argv[ i + 1 ] ); - } - - if ( identifier.isEmpty() ) { - kDebug( 5250 ) << "Identifier argument missing"; - exit( 1 ); - } - - sAppName = qstrdup( identifier.toLatin1().constData() ); - KCmdLineArgs::init( argc, argv, sAppName, 0, - ki18nc("@title, application name", "Akonadi Resource"), "0.1", - ki18nc("@title, application description", "Akonadi Resource") ); - - KCmdLineOptions options; - options.add("identifier ", - ki18nc("@label, commandline option", "Resource identifier")); - KCmdLineArgs::addCmdLineOptions( options ); - - return identifier; -} - -int ResourceBase::init( ResourceBase *r ) -{ - QApplication::setQuitOnLastWindowClosed( false ); - int rv = kapp->exec(); - delete r; - delete[] sAppName; - return rv; -} - -void ResourceBase::itemRetrieved( const Item &item ) -{ - Q_D( ResourceBase ); - Q_ASSERT( d->scheduler->currentTask().type == ResourceScheduler::FetchItem ); - if ( !item.isValid() ) { - QDBusMessage reply( d->scheduler->currentTask().dbusMsg ); - reply << false; - QDBusConnection::sessionBus().send( reply ); - d->scheduler->taskDone(); - return; - } - - Item i( item ); - QSet requestedParts = d->scheduler->currentTask().itemParts; - foreach ( const QByteArray &part, requestedParts ) { - if ( !item.loadedPayloadParts().contains( part ) ) { - kWarning( 5250 ) << "Item does not provide part" << part; - } - } - - ItemModifyJob *job = new ItemModifyJob( i ); - // FIXME: remove once the item with which we call retrieveItem() has a revision number - job->disableRevisionCheck(); - connect( job, SIGNAL(result(KJob*)), SLOT(slotDeliveryDone(KJob*)) ); -} - -void ResourceBasePrivate::slotDeliveryDone(KJob * job) -{ - Q_Q( ResourceBase ); - Q_ASSERT( scheduler->currentTask().type == ResourceScheduler::FetchItem ); - QDBusMessage reply( scheduler->currentTask().dbusMsg ); - if ( job->error() ) { - emit q->error( QLatin1String( "Error while creating item: " ) + job->errorString() ); - reply << false; - } else { - reply << true; - } - QDBusConnection::sessionBus().send( reply ); - scheduler->taskDone(); -} - -void ResourceBase::changeCommitted(const Item& item) -{ - Q_D( ResourceBase ); - ItemModifyJob *job = new ItemModifyJob( item ); - job->d_func()->setClean(); - job->disableRevisionCheck(); // TODO: remove, but where/how do we handle the error? - d->changeProcessed(); -} - -void ResourceBase::changeCommitted( const Collection &collection ) -{ - Q_D( ResourceBase ); - CollectionModifyJob *job = new CollectionModifyJob( collection ); - Q_UNUSED( job ); - //TODO: error checking - d->changeProcessed(); -} - -bool ResourceBase::requestItemDelivery( qint64 uid, const QString & remoteId, - const QString &mimeType, const QStringList &_parts ) -{ - Q_D( ResourceBase ); - if ( !isOnline() ) { - emit error( i18nc( "@info", "Cannot fetch item in offline mode." ) ); - return false; - } - - setDelayedReply( true ); - // FIXME: we need at least the revision number too - Item item( uid ); - item.setMimeType( mimeType ); - item.setRemoteId( remoteId ); - - QSet parts; - Q_FOREACH( const QString &str, _parts ) - parts.insert( str.toLatin1() ); - - d->scheduler->scheduleItemFetch( item, parts, message().createReply() ); - - return true; -} - -void ResourceBase::collectionsRetrieved(const Collection::List & collections) -{ - Q_D( ResourceBase ); - CollectionSync *syncer = new CollectionSync( d->mId ); - syncer->setRemoteCollections( collections ); - connect( syncer, SIGNAL(result(KJob*)), SLOT(slotCollectionSyncDone(KJob*)) ); -} - -void ResourceBase::collectionsRetrievedIncremental(const Collection::List & changedCollections, const Collection::List & removedCollections) -{ - Q_D( ResourceBase ); - CollectionSync *syncer = new CollectionSync( d->mId ); - syncer->setRemoteCollections( changedCollections, removedCollections ); - connect( syncer, SIGNAL(result(KJob*)), SLOT(slotCollectionSyncDone(KJob*)) ); -} - -void ResourceBasePrivate::slotCollectionSyncDone(KJob * job) -{ - Q_Q( ResourceBase ); - if ( job->error() ) { - emit q->error( job->errorString() ); - } else { - if ( scheduler->currentTask().type == ResourceScheduler::SyncAll ) { - CollectionFetchJob *list = new CollectionFetchJob( Collection::root(), CollectionFetchJob::Recursive ); - list->setResource( mId ); - q->connect( list, SIGNAL(result(KJob*)), q, SLOT(slotLocalListDone(KJob*)) ); - return; - } - } - if ( scheduler->isEmpty() ) - emit q->status( AgentBase::Idle ); - scheduler->taskDone(); -} - -void ResourceBasePrivate::slotLocalListDone(KJob * job) -{ - Q_Q( ResourceBase ); - if ( job->error() ) { - emit q->error( job->errorString() ); - } else { - Collection::List cols = static_cast( job )->collections(); - foreach ( const Collection &col, cols ) { - scheduler->scheduleSync( col ); - } - } - scheduler->taskDone(); -} - -void ResourceBasePrivate::slotSynchronizeCollection( const Collection &col ) -{ - Q_Q( ResourceBase ); - currentCollection = col; - // check if this collection actually can contain anything - QStringList contentTypes = currentCollection.contentMimeTypes(); - contentTypes.removeAll( Collection::mimeType() ); - if ( !contentTypes.isEmpty() ) { - emit q->status( AgentBase::Running, i18nc( "@info:status", "Syncing collection '%1'", currentCollection.name() ) ); - q->retrieveItems( currentCollection ); - return; - } - scheduler->taskDone(); -} - -void ResourceBase::itemsRetrievalDone() -{ - Q_D( ResourceBase ); - // streaming enabled, so finalize the sync - if ( d->mItemSyncer ) { - d->mItemSyncer->deliveryDone(); - } - // user did the sync himself, we are done now - else { - if ( d->scheduler->isEmpty() ) - emit status( Idle ); - d->scheduler->taskDone(); - } -} - -Collection ResourceBase::currentCollection() const -{ - Q_D( const ResourceBase ); - Q_ASSERT_X( d->scheduler->currentTask().type == ResourceScheduler::SyncCollection , - "ResourceBase::currentCollection()", - "Trying to access current collection although no item retrieval is in progress" ); - return d->currentCollection; -} - -Item ResourceBase::currentItem() const -{ - Q_D( const ResourceBase ); - Q_ASSERT_X( d->scheduler->currentTask().type == ResourceScheduler::FetchItem , - "ResourceBase::currentItem()", - "Trying to access current item although no item retrieval is in progress" ); - return d->scheduler->currentTask().item; -} - -void ResourceBase::synchronizeCollectionTree() -{ - d_func()->scheduler->scheduleCollectionTreeSync(); -} - -void ResourceBase::cancelTask() -{ - d_func()->changeProcessed(); -} - -void ResourceBase::cancelTask( const QString &msg ) -{ - cancelTask(); - - emit error( msg ); -} - -void ResourceBase::doSetOnline( bool state ) -{ - d_func()->scheduler->setOnline( state ); -} - -void ResourceBase::synchronizeCollection(qint64 collectionId ) -{ - CollectionFetchJob* job = new CollectionFetchJob( Collection(collectionId), CollectionFetchJob::Base ); - job->setResource( identifier() ); - connect( job, SIGNAL(result(KJob*)), SLOT(slotCollectionListDone(KJob*)) ); -} - -void ResourceBasePrivate::slotCollectionListDone( KJob *job ) -{ - if ( !job->error() ) { - Collection::List list = static_cast( job )->collections(); - if ( !list.isEmpty() ) { - Collection col = list.first(); - scheduler->scheduleSync( col ); - } - } - // TODO: error handling -} - -void ResourceBase::setTotalItems( int amount ) -{ - kDebug() << amount; - Q_D( ResourceBase ); - setItemStreamingEnabled( true ); - d->mItemSyncer->setTotalItems( amount ); -} - -void ResourceBase::setItemStreamingEnabled( bool enable ) -{ - Q_D( ResourceBase ); - Q_ASSERT_X( d->scheduler->currentTask().type == ResourceScheduler::SyncCollection, - "ResourceBase::setItemStreamingEnabled()", - "Calling setItemStreamingEnabled() although no item retrieval is in progress" ); - if ( !d->mItemSyncer ) { - d->mItemSyncer = new ItemSync( currentCollection() ); - connect( d->mItemSyncer, SIGNAL(percent(KJob*,unsigned long)), SLOT(slotPercent(KJob*,unsigned long)) ); - connect( d->mItemSyncer, SIGNAL(result(KJob*)), SLOT(slotItemSyncDone(KJob*)) ); - } - d->mItemSyncer->setStreamingEnabled( enable ); -} - -void ResourceBase::itemsRetrieved( const Item::List &items ) -{ - Q_D( ResourceBase ); - Q_ASSERT_X( d->scheduler->currentTask().type == ResourceScheduler::SyncCollection, - "ResourceBase::itemsRetrieved()", - "Calling itemsRetrieved() although no item retrieval is in progress" ); - if ( !d->mItemSyncer ) { - d->mItemSyncer = new ItemSync( currentCollection() ); - connect( d->mItemSyncer, SIGNAL(percent(KJob*,unsigned long)), SLOT(slotPercent(KJob*,unsigned long)) ); - connect( d->mItemSyncer, SIGNAL(result(KJob*)), SLOT(slotItemSyncDone(KJob*)) ); - } - d->mItemSyncer->setFullSyncItems( items ); -} - -void ResourceBase::itemsRetrievedIncremental(const Item::List &changedItems, const Item::List &removedItems) -{ - Q_D( ResourceBase ); - Q_ASSERT_X( d->scheduler->currentTask().type == ResourceScheduler::SyncCollection, - "ResourceBase::itemsRetrievedIncremental()", - "Calling itemsRetrievedIncremental() although no item retrieval is in progress" ); - if ( !d->mItemSyncer ) { - d->mItemSyncer = new ItemSync( currentCollection() ); - connect( d->mItemSyncer, SIGNAL(percent(KJob*,unsigned long)), SLOT(slotPercent(KJob*,unsigned long)) ); - connect( d->mItemSyncer, SIGNAL(result(KJob*)), SLOT(slotItemSyncDone(KJob*)) ); - } - d->mItemSyncer->setIncrementalSyncItems( changedItems, removedItems ); -} - -void ResourceBasePrivate::slotItemSyncDone( KJob *job ) -{ - mItemSyncer = 0; - Q_Q( ResourceBase ); - if ( job->error() ) { - emit q->error( job->errorString() ); - } - if ( scheduler->isEmpty() ) - emit q->status( AgentBase::Idle ); - scheduler->taskDone(); -} - -void ResourceBasePrivate::slotPercent( KJob *job, unsigned long percent ) -{ - Q_Q( ResourceBase ); - Q_UNUSED( job ); - emit q->percent( percent ); -} - -#include "resourcebase.moc" diff --git a/akonadi/resourcebase.h b/akonadi/resourcebase.h deleted file mode 100644 index 2c224c149..000000000 --- a/akonadi/resourcebase.h +++ /dev/null @@ -1,418 +0,0 @@ -/* - This file is part of akonadiresources. - - Copyright (c) 2006 Till Adam - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_RESOURCEBASE_H -#define AKONADI_RESOURCEBASE_H - -#include "akonadi_export.h" - -#include -#include -#include - -class KJob; -class ResourceAdaptor; - -namespace Akonadi { - -class ResourceBasePrivate; - -/** - * @short The base class for all Akonadi resources. - * - * This class should be used as a base class by all resource agents, - * because it encapsulates large parts of the protocol between - * resource agent, agent manager and the Akonadi storage. - * - * It provides many convenience methods to make implementing a - * new Akonadi resource agent as simple as possible. - * - *

How to write a resource

- * - * The following provides an overview of what you need to do to implement - * your own Akonadi resource. In the following, the term 'backend' refers - * to the entity the resource connects with Akonadi, be it a single file - * or a remote server. - * - * @todo Complete this (online/offline state management) - * - *
Basic %Resource Framework
- * - * The following is needed to create a new resource: - * - A new class deriving from Akonadi::ResourceBase, implementing at least all - * pure-virtual methods, see below for further details. - * - call init() in your main() function. - * - a .desktop file similar to the following example - * \code - * [Desktop Entry] - * Encoding=UTF-8 - * Name=My Akonadi Resource - * Type=AkonadiResource - * Exec=akonadi_my_resource - * Icon=my-icon - * - * X-Akonadi-MimeTypes= - * X-Akonadi-Capabilities=Resource - * X-Akonadi-Identifier=akonadi_my_resource - * \endcode - * - *
Handling PIM Items
- * - * To follow item changes in the backend, the following steps are necessary: - * - Implement retrieveItems() to synchronize all items in the given - * collection. If the backend supports incremental retrieval, - * implementing support for that is recommended to improve performance. - * - Convert the items provided by the backend to Akonadi items. - * This typically happens either in retrieveItems() if you retrieved - * the collection synchronously (not recommended for network backends) or - * in the result slot of the asynchronous retrieval job. - * Converting means to create Akonadi::Item objects for every retrieved - * item. It's very important that every object has its remote identifier set. - * - Call itemsRetrieved() or itemsRetrievedIncremental() respectively - * with the item objects created above. The Akonadi storage will then be - * updated automatically. Note that it is usually not necessary to manipulate - * any item in the Akonadi storage manually. - * - * To fetch item data on demand, the method retrieveItem() needs to be - * reimplemented. Fetch the requested data there and call itemRetrieved() - * with the result item. - * - * To write local changes back to the backend, you need to re-implement - * the following three methods: - * - itemAdded() - * - itemChanged() - * - itemRemoved() - * Once you have handled changes in these methods call changeCommitted(). - * These methods are called whenever a local item related to this resource is - * added, modified or deleted. They are only called if the resource is online, otherwise - * all changes are recorded and replayed as soon the resource is online again. - * - *
Handling Collections
- * - * To follow collection changes in the backend, the following steps are necessary: - * - Implement retrieveCollections() to retrieve collections from the backend. - * If the backend supports incremental collections updates, implementing - * support for that is recommended to improve performance. - * - Convert the collections of the backend to Akonadi collections. - * This typically happens either in retrieveCollections() if you retrieved - * the collection synchronously (not recommended for network backends) or - * in the result slot of the asynchronous retrieval job. - * Converting means to create Akonadi::Collection objects for every retrieved - * collection. It's very important that every object has its remote identifier - * and its parent remote identifier set. - * - Call collectionsRetrieved() or collectionsRetrievedIncremental() respectively - * with the collection objects created above. The Akonadi storage will then be - * updated automatically. Note that it is usually not necessary to manipulate - * any collection in the Akonadi storage manually. - * - * - * To write local collection changes back to the backend, you need to re-implement - * the following three methods: - * - collectionAdded() - * - collectionChanged() - * - collectionRemoved() - * Once you have handled changes in these methods call changeCommitted(). - * These methods are called whenever a local collection related to this resource is - * added, modified or deleted. They are only called if the resource is online, otherwise - * all changes are recorded and replayed as soon the resource is online again. - * - * @todo Convenience base class for collection-less resources - */ - // FIXME_API: API dox need to be updated for Observer approach (kevin) -class AKONADI_EXPORT ResourceBase : public AgentBase -{ - Q_OBJECT - - public: - /** - * Use this method in the main function of your resource - * application to initialize your resource subclass. - * This method also takes care of creating a KApplication - * object and parsing command line arguments. - * - * @note In case the given class is also derived from AgentBase::Observer - * it gets registered as its own observer (see AgentBase::Observer), e.g. - * resourceInstance->registerObserver( resourceInstance ); - * - * @code - * - * class MyResource : public ResourceBase - * { - * ... - * }; - * - * int main( int argc, char **argv ) - * { - * return ResourceBase::init( argc, argv ); - * } - * - * @endcode - */ - template - static int init( int argc, char **argv ) - { - const QString id = parseArguments( argc, argv ); - KApplication app; - T* r = new T( id ); - - // check if T also inherits AgentBase::Observer and - // if it does, automatically register it on itself - Observer *observer = dynamic_cast( r ); - if ( observer != 0 ) - r->registerObserver( observer ); - return init( r ); - } - - /** - * This method is used to set the name of the resource. - */ - //FIXME_API: make sure location is renamed to this by resourcebase - void setName( const QString &name ); - - /** - * Returns the name of the resource. - */ - QString name() const; - - Q_SIGNALS: - /** - * This signal is emitted whenever the name of the resource has changed. - * - * @param name The new name of the resource. - */ - void nameChanged( const QString &name ); - - protected Q_SLOTS: - /** - * Retrieve the collection tree from the remote server and supply it via - * collectionsRetrieved() or collectionsRetrievedIncremental(). - * @see collectionsRetrieved(), collectionsRetrievedIncremental() - */ - virtual void retrieveCollections() = 0; - - /** - * Retrieve all (new/changed) items in collection @p collection. - * It is recommended to use incremental retrieval if the backend supports that - * and provide the result by calling itemsRetrievedIncremental(). - * If incremental retrieval is not possible, provide the full listing by calling - * itemsRetrieved( const Item::List& ). - * In any case, ensure that all items have a correctly set remote identifier - * to allow synchronizing with already locally existing items. - * In case you don't want to use the built-in item syncing code, store the retrived - * items manually and call itemsRetrieved() once you are done. - * @param collection The collection to sync. - * @see itemsRetrieved( const Item::List &), itemsRetrievedIncremental(), itemsRetrieved(), currentCollection() - */ - virtual void retrieveItems( const Akonadi::Collection &collection ) = 0; - - /** - * Retrieve a single item from the backend. The item to retrieve is provided as @p item. - * Add the requested payload parts and call itemRetrieved() when done. - * @param item The empty item which payload should be retrieved. Use this object when delivering - * the result instead of creating a new item to ensure conflict detection to work. - * @param parts The item parts that should be retrieved. - * @return false if there is an immediate error when retrieving the item. - * @see itemRetrieved() - */ - virtual bool retrieveItem( const Akonadi::Item &item, const QSet &parts ) = 0; - - protected: - /** - * Creates a base resource. - * - * @param id The instance id of the resource. - */ - ResourceBase( const QString & id ); - - /** - * Destroys the base resource. - */ - ~ResourceBase(); - - /** - * Call this method from retrieveItem() once the result is available. - * - * @param item The retrieved item. - */ - void itemRetrieved( const Item &item ); - - /** - * Resets the dirty flag of the given item and updates the remote id. - * - * Call whenever you have successfully written changes back to the server. - * This implicitly calls changeProcessed(). - * @param item The changed item. - */ - void changeCommitted( const Item &item ); - - /** - * Call whenever you have successfully handled or ignored a collection - * change notification. - * - * This will update the remote identifier of @p collection if necessary, - * as well as any other collection attributes. - * This implicitly calls changeProcessed(). - * @param collection The collection which changes have been handled. - */ - void changeCommitted( const Collection &collection ); - - /** - * Call this to supply the full folder tree retrieved from the remote server. - * - * @param collections A list of collections. - * @see collectionsRetrievedIncremental() - */ - void collectionsRetrieved( const Collection::List &collections ); - - /** - * Call this to supply incrementally retrieved collections from the remote server. - * - * @param changedCollections Collections that have been added or changed. - * @param removedCollections Collections that have been deleted. - * @see collectionsRetrieved() - */ - void collectionsRetrievedIncremental( const Collection::List &changedCollections, - const Collection::List &removedCollections ); - - /** - * Call this method to supply the full collection listing from the remote server. - * - * If the remote server supports incremental listing, it's strongly - * recommended to use itemsRetrievedIncremental() instead. - * @param items A list of items. - * @see itemsRetrievedIncremental(). - */ - void itemsRetrieved( const Item::List &items ); - - /** - * Call this method when you want to use the itemsRetrieved() method - * in streaming mode and indicate the amount of items that will arrive - * that way. - * @deprecated Use setItemStreamingEnabled( true ) + itemsRetrieved[Incremental]() - * + itemsRetrieved() instead. - */ - void setTotalItems( int amount ); - - /** - * Enable item streaming. - * Item streaming is disabled by default. - * @param enable @c true if items are delivered in chunks rather in one big block. - */ - void setItemStreamingEnabled( bool enable ); - - /** - * Call this method to supply incrementally retrieved items from the remote server. - * - * @param changedItems Items changed in the backend. - * @param removedItems Items removed from the backend. - */ - void itemsRetrievedIncremental( const Item::List &changedItems, - const Item::List &removedItems ); - - /** - * Call this method to indicate you finished synchronizing the current collection. - * - * This is not needed if you use the built in syncing without item streaming - * and call itemsRetrieved() or itemsRetrievedIncremental() instead. - * If item streaming is enabled, call this method once all items have been delivered - * using itemsRetrieved() or itemsRetrievedIncremental(). - * @see retrieveItems() - */ - void itemsRetrievalDone(); - - /** - * Returns the collection that is currently synchronized. - */ - Collection currentCollection() const; - - /** - * Returns the item that is currently retrieved. - */ - Item currentItem() const; - - /** - * This method is called whenever the resource should start synchronize all data. - */ - void synchronize(); - - /** - * This method is called whenever the collection with the given @p id - * shall be synchronized. - */ - void synchronizeCollection( qint64 id ); - - /** - * Refetches the Collections. - */ - void synchronizeCollectionTree(); - - /** - * Stops the execution of the current task and continues with the next one. - */ - void cancelTask(); - - /** - * Stops the execution of the current task and continues with the next one. - * Additionally an error message is emitted. - */ - void cancelTask( const QString &error ); - - /** - * Inherited from AgentBase. - */ - void doSetOnline( bool online ); - - private: - static QString parseArguments( int, char** ); - static int init( ResourceBase *r ); - - // dbus resource interface - friend class ::ResourceAdaptor; - - bool requestItemDelivery( qint64 uid, const QString &remoteId, const QString &mimeType, const QStringList &parts ); - - private: - Q_DECLARE_PRIVATE( ResourceBase ) - - Q_PRIVATE_SLOT( d_func(), void slotDeliveryDone( KJob* ) ) - Q_PRIVATE_SLOT( d_func(), void slotCollectionSyncDone( KJob* ) ) - Q_PRIVATE_SLOT( d_func(), void slotLocalListDone( KJob* ) ) - Q_PRIVATE_SLOT( d_func(), void slotSynchronizeCollection( const Akonadi::Collection& ) ) - Q_PRIVATE_SLOT( d_func(), void slotCollectionListDone( KJob* ) ) - Q_PRIVATE_SLOT( d_func(), void slotItemSyncDone( KJob* ) ) - Q_PRIVATE_SLOT( d_func(), void slotPercent( KJob*, unsigned long ) ) -}; - -} - -#ifndef AKONADI_RESOURCE_MAIN -/** - * Convenience Macro for the most common main() function for Akonadi resources. - */ -#define AKONADI_RESOURCE_MAIN( resourceClass ) \ - int main( int argc, char **argv ) \ - { \ - return Akonadi::ResourceBase::init( argc, argv ); \ - } -#endif - -#endif diff --git a/akonadi/resourcescheduler.cpp b/akonadi/resourcescheduler.cpp deleted file mode 100644 index a0b344202..000000000 --- a/akonadi/resourcescheduler.cpp +++ /dev/null @@ -1,141 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "resourcescheduler.h" - -#include - -#include - -using namespace Akonadi; - -ResourceScheduler::ResourceScheduler( QObject *parent ) : - QObject( parent ), - mOnline( false ) -{ -} - -void ResourceScheduler::scheduleFullSync() -{ - Task t; - t.type = SyncAll; - mTaskList << t; - scheduleNext(); -} - -void ResourceScheduler::scheduleCollectionTreeSync() -{ - Task t; - t.type = SyncCollectionTree; - mTaskList << t; - scheduleNext(); -} - -void ResourceScheduler::scheduleSync(const Collection & col) -{ - Task t; - t.type = SyncCollection; - t.collection = col; - mTaskList << t; - scheduleNext(); -} - -void ResourceScheduler::scheduleItemFetch(const Item & item, const QSet &parts, const QDBusMessage & msg) -{ - Task t; - t.type = FetchItem; - t.item = item; - t.itemParts = parts; - t.dbusMsg = msg; - mTaskList << t; - scheduleNext(); -} - -void ResourceScheduler::scheduleChangeReplay() -{ - Task t; - t.type = ChangeReplay; - if ( mTaskList.contains( t ) ) - return; - mTaskList << t; - scheduleNext(); -} - -void ResourceScheduler::taskDone() -{ - mCurrentTask = Task(); - scheduleNext(); -} - -bool ResourceScheduler::isEmpty() -{ - return mTaskList.isEmpty(); -} - -void ResourceScheduler::scheduleNext() -{ - if ( mCurrentTask.type != Invalid || mTaskList.isEmpty() || !mOnline ) - return; - QTimer::singleShot( 0, this, SLOT(executeNext()) ); -} - -void ResourceScheduler::executeNext() -{ - mCurrentTask = mTaskList.takeFirst(); - switch ( mCurrentTask.type ) { - case SyncAll: - emit executeFullSync(); - break; - case SyncCollectionTree: - emit executeCollectionTreeSync(); - break; - case SyncCollection: - emit executeCollectionSync( mCurrentTask.collection ); - break; - case FetchItem: - emit executeItemFetch( mCurrentTask.item, mCurrentTask.itemParts ); - break; - case ChangeReplay: - emit executeChangeReplay(); - break; - default: - Q_ASSERT( false ); - } -} - -ResourceScheduler::Task ResourceScheduler::currentTask() const -{ - return mCurrentTask; -} - -void ResourceScheduler::setOnline(bool state) -{ - if ( mOnline == state ) - return; - mOnline = state; - if ( mOnline ) { - scheduleNext(); - } else if ( mCurrentTask.type != Invalid ) { - // abort running task - mTaskList.prepend( mCurrentTask ); - mCurrentTask = Task(); - } -} - -#include "resourcescheduler.moc" diff --git a/akonadi/resourcescheduler.h b/akonadi/resourcescheduler.h deleted file mode 100644 index d9e140c9e..000000000 --- a/akonadi/resourcescheduler.h +++ /dev/null @@ -1,142 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_RESOURCESCHEDULER_H -#define AKONADI_RESOURCESCHEDULER_H - -#include -#include - -#include -#include -#include - -namespace Akonadi { - -/** - @internal - - Manages synchronization and fetch requests for a resource. - - @todo Attach to the ResourceBase Monitor, -*/ -class ResourceScheduler : public QObject -{ - Q_OBJECT - - public: - enum TaskType { - Invalid, - SyncAll, - SyncCollectionTree, - SyncCollection, - FetchItem, - ChangeReplay - }; - - class Task { - public: - Task() : type( Invalid ) {} - TaskType type; - Collection collection; - Item item; - QSet itemParts; - QDBusMessage dbusMsg; - - bool operator==( const Task &other ) const - { - return type == other.type - && collection == other.collection - && item == other.item - && itemParts == other.itemParts; - } - }; - - ResourceScheduler( QObject *parent = 0 ); - - /** - Schedules a full synchronization. - */ - void scheduleFullSync(); - - /** - Schedules a collection tree sync. - */ - void scheduleCollectionTreeSync(); - - /** - Schedules the synchronization of a single collection. - @param col The collection to synchronize. - */ - void scheduleSync( const Collection &col ); - - /** - Schedules fetching of a single PIM item. - @param item The item to fetch. - @param parts List of names of the parts of the item to fetch. - @param msg The associated D-Bus message. - */ - void scheduleItemFetch( const Item &item, const QSet &parts, const QDBusMessage &msg ); - - /** - The current task has been finished - */ - void taskDone(); - - /** - Returns true if no tasks are running or in the queue. - */ - bool isEmpty(); - - /** - Returns the current task. - */ - Task currentTask() const; - - /** - Sets the online state. - */ - void setOnline( bool state ); - - public Q_SLOTS: - /** - Schedules replaying changes. - */ - void scheduleChangeReplay(); - - Q_SIGNALS: - void executeFullSync(); - void executeCollectionSync( const Akonadi::Collection &col ); - void executeCollectionTreeSync(); - void executeItemFetch( const Akonadi::Item &item, const QSet &parts ); - void executeChangeReplay(); - - private slots: - void scheduleNext(); - void executeNext(); - - private: - QList mTaskList; - Task mCurrentTask; - bool mOnline; -}; - -} - -#endif diff --git a/akonadi/searchcreatejob.cpp b/akonadi/searchcreatejob.cpp deleted file mode 100644 index 0feb717eb..000000000 --- a/akonadi/searchcreatejob.cpp +++ /dev/null @@ -1,64 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "searchcreatejob.h" - -#include "imapparser_p.h" -#include "job_p.h" - -using namespace Akonadi; - -class Akonadi::SearchCreateJobPrivate : public JobPrivate -{ - public: - SearchCreateJobPrivate( SearchCreateJob *parent ) - : JobPrivate( parent ) - { - } - - QString mName; - QString mQuery; -}; - -SearchCreateJob::SearchCreateJob(const QString & name, const QString & query, QObject * parent) - : Job( new SearchCreateJobPrivate( this ), parent ) -{ - Q_D( SearchCreateJob ); - - d->mName = name; - d->mQuery = query; -} - -SearchCreateJob::~SearchCreateJob() -{ -} - -void SearchCreateJob::doStart() -{ - Q_D( SearchCreateJob ); - - QByteArray command = d->newTag() + " SEARCH_STORE "; - command += ImapParser::quote( d->mName.toUtf8() ); - command += ' '; - command += ImapParser::quote( d->mQuery.toUtf8() ); - command += '\n'; - d->writeData( command ); -} - -#include "searchcreatejob.moc" diff --git a/akonadi/searchcreatejob.h b/akonadi/searchcreatejob.h deleted file mode 100644 index adaf19677..000000000 --- a/akonadi/searchcreatejob.h +++ /dev/null @@ -1,80 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_SEARCHCREATEJOB_H -#define AKONADI_SEARCHCREATEJOB_H - -#include - -namespace Akonadi { - -class SearchCreateJobPrivate; - -/** - * @short Job that creates a virtual/search collection in the Akonadi storage. - * - * This job creates so called virtual or search collections, which don't contain - * real data, but references to items that match a given search query. - * - * @code - * - * const QString name = "My search folder"; - * const QString query = "..."; - * - * Akonadi::SearchCreateJob *job = new Akonadi::SearchCreateJob( name, query ); - * if ( job->exec() ) - * qDebug() << "Created search folder successfully"; - * else - * qDebug() << "Error occurred"; - * - * @endcode - * - * @todo Add method that returns the new search collection. - * - * @author Volker Krause - */ -class AKONADI_EXPORT SearchCreateJob : public Job -{ - Q_OBJECT - - public: - /** - * Creates a search create job. - * - * @param name The name of the search collection. - * @param query The search query (format not defined yet). - * @param parent The parent object. - */ - SearchCreateJob( const QString &name, const QString &query, QObject *parent = 0 ); - - /** - * Destroys the search create job. - */ - ~SearchCreateJob(); - - protected: - void doStart(); - - private: - Q_DECLARE_PRIVATE( SearchCreateJob ) -}; - -} - -#endif diff --git a/akonadi/session.cpp b/akonadi/session.cpp deleted file mode 100644 index 0e28ae7b4..000000000 --- a/akonadi/session.cpp +++ /dev/null @@ -1,284 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "session.h" -#include "session_p.h" - -#include "imapparser_p.h" -#include "job.h" -#include "job_p.h" -#include "xdgbasedirs_p.h" - -#include -#include - -#include -#include -#include -#include - -#include - -#define PIPELINE_LENGTH 2 - -using namespace Akonadi; - - -//@cond PRIVATE - -static const int minimumProtocolVersion = 2; - -void SessionPrivate::startNext() -{ - QTimer::singleShot( 0, mParent, SLOT(doStartNext()) ); -} - -void SessionPrivate::reconnect() -{ - // should be checking connection method and value validity - if ( socket->state() != QLocalSocket::ConnectedState && - socket->state() != QLocalSocket::ConnectingState ) { -#ifdef Q_OS_WIN //krazy:exclude=cpp - const QString namedPipe = mConnectionSettings->value( QLatin1String( "Data/NamedPipe" ), QLatin1String( "Akonadi" ) ).toString(); - socket->connectToServer( namedPipe ); -#else - const QString defaultSocketDir = XdgBaseDirs::saveDir( "data", QLatin1String( "akonadi" ) ); - const QString path = mConnectionSettings->value( QLatin1String( "Data/UnixPath" ), defaultSocketDir + QLatin1String( "/akonadiserver.socket" ) ).toString(); - socket->connectToServer( path ); -#endif - } -} - -void SessionPrivate::socketError() -{ - if ( currentJob ) - currentJob->d_ptr->lostConnection(); - connected = false; - QTimer::singleShot( 1000, mParent, SLOT(reconnect()) ); -} - -void SessionPrivate::dataReceived() -{ - while ( socket->bytesAvailable() > 0 ) { - if ( parser->continuationSize() > 1 ) { - const QByteArray data = socket->read( qMin( socket->bytesAvailable(), parser->continuationSize() - 1 ) ); - parser->parseBlock( data ); - } else if ( socket->canReadLine() ) { - if ( !parser->parseNextLine( socket->readLine() ) ) - continue; // response not yet completed - - // handle login response - if ( parser->tag() == QByteArray("0") ) { - if ( parser->data().startsWith( "OK" ) ) { - connected = true; - startNext(); - } else { - kWarning( 5250 ) << "Unable to login to Akonadi server:" << parser->data(); - socket->close(); - QTimer::singleShot( 1000, mParent, SLOT(reconnect()) ); - } - } - - // send login command - if ( parser->tag() == "*" && parser->data().startsWith( "OK Akonadi" ) ) { - const int pos = parser->data().indexOf( "[PROTOCOL" ); - if ( pos > 0 ) { - qint64 tmp = 0; - ImapParser::parseNumber( parser->data(), tmp, 0, pos + 9 ); - protocolVersion = tmp; - } - kDebug( 5250 ) << "Server protocol version is:" << protocolVersion; - - writeData( "0 LOGIN " + sessionId + '\n' ); - - // work for the current job - } else { - if ( currentJob ) - currentJob->d_ptr->handleResponse( parser->tag(), parser->data() ); - } - - // reset parser stuff - parser->reset(); - } else { - break; // nothing we can do for now - } - } -} - -bool SessionPrivate::canPipelineNext() -{ - if ( queue.isEmpty() || pipeline.count() >= PIPELINE_LENGTH ) - return false; - if ( pipeline.isEmpty() && currentJob ) - return currentJob->d_ptr->mWriteFinished; - if ( !pipeline.isEmpty() ) - return pipeline.last()->d_ptr->mWriteFinished; - return false; -} - -void SessionPrivate::doStartNext() -{ - if ( !connected || (queue.isEmpty() && pipeline.isEmpty()) ) - return; - if ( canPipelineNext() ) { - Akonadi::Job *nextJob = queue.dequeue(); - pipeline.enqueue( nextJob ); - startJob( nextJob ); - } - if ( jobRunning ) - return; - jobRunning = true; - if ( !pipeline.isEmpty() ) { - currentJob = pipeline.dequeue(); - } else { - currentJob = queue.dequeue(); - startJob( currentJob ); - } -} - -void SessionPrivate::startJob( Job *job ) -{ - if ( protocolVersion < minimumProtocolVersion ) { - job->setError( Job::ProtocolVersionMismatch ); - job->setErrorText( i18n( "Protocol version %1 found, expected at least %2", protocolVersion, minimumProtocolVersion ) ); - job->emitResult(); - } else { - job->d_ptr->startQueued(); - } -} - -void SessionPrivate::jobDone(KJob * job) -{ - if( job == currentJob ) { - if ( pipeline.isEmpty() ) { - jobRunning = false; - currentJob = 0; - } else { - currentJob = pipeline.dequeue(); - } - startNext(); - } - // ### better handle the other cases too, user might have canceled jobs - else { - kDebug( 5250 ) << job << "Non-current job finished."; - } -} - -void SessionPrivate::jobWriteFinished( Akonadi::Job* job ) -{ - Q_ASSERT( (job == currentJob && pipeline.isEmpty()) || (job = pipeline.last()) ); - startNext(); -} - -void SessionPrivate::addJob(Job * job) -{ - queue.append( job ); - QObject::connect( job, SIGNAL(result(KJob*)), mParent, SLOT(jobDone(KJob*)) ); - QObject::connect( job, SIGNAL(writeFinished(Akonadi::Job*)), mParent, SLOT(jobWriteFinished(Akonadi::Job*)) ); - startNext(); -} - -int SessionPrivate::nextTag() -{ - return theNextTag++; -} - -void SessionPrivate::writeData(const QByteArray & data) -{ - socket->write( data ); -} - -//@endcond - - -Session::Session(const QByteArray & sessionId, QObject * parent) : - QObject( parent ), - d( new SessionPrivate( this ) ) -{ - if ( !sessionId.isEmpty() ) - d->sessionId = sessionId; - else - d->sessionId = QByteArray::number( qrand() ); - - d->connected = false; - d->theNextTag = 1; - d->currentJob = 0; - d->jobRunning = false; - - const QString connectionConfigFile = XdgBaseDirs::akonadiConnectionConfigFile(); - - QFileInfo fileInfo( connectionConfigFile ); - if ( !fileInfo.exists() ) { - kWarning( 5250 ) << "Akonadi Client Session: connection config file '" - << "akonadi/akonadiconnectionrc can not be found in '" - << XdgBaseDirs::homePath( "config" ) << "' nor in any of " - << XdgBaseDirs::systemPathList( "config" ); - } - - d->mConnectionSettings = new QSettings( connectionConfigFile, QSettings::IniFormat ); - - // should check connection method - d->socket = new QLocalSocket( this ); - - connect( d->socket, SIGNAL(disconnected()), SLOT(socketError()) ); - connect( d->socket, SIGNAL(error(QLocalSocket::LocalSocketError)), SLOT(socketError()) ); - connect( d->socket, SIGNAL(readyRead()), SLOT(dataReceived()) ); - d->reconnect(); -} - -Session::~Session() -{ - clear(); - delete d; -} - -QByteArray Session::sessionId() const -{ - return d->sessionId; -} - -QThreadStorage instances; - -void SessionPrivate::createDefaultSession( const QByteArray &sessionId ) -{ - Q_ASSERT_X( !sessionId.isEmpty(), "SessionPrivate::createDefaultSession", - "You tried to create a default session with empty session id!" ); - Q_ASSERT_X( !instances.hasLocalData(), "SessionPrivate::createDefaultSession", - "You tried to create a default session twice!" ); - - instances.setLocalData( new Session( sessionId ) ); -} - -Session* Session::defaultSession() -{ - if ( !instances.hasLocalData() ) - instances.setLocalData( new Session() ); - return instances.localData(); -} - -void Session::clear() -{ - foreach ( Job* job, d->queue ) - job->kill( KJob::EmitResult ); - d->queue.clear(); - if ( d->currentJob ) - d->currentJob->kill( KJob::EmitResult ); -} - -#include "session.moc" diff --git a/akonadi/session.h b/akonadi/session.h deleted file mode 100644 index 91462aefa..000000000 --- a/akonadi/session.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_SESSION_H -#define AKONADI_SESSION_H - -#include "akonadi_export.h" -#include - -class KJob; - -namespace Akonadi { - -class Job; -class SessionPrivate; - -/** - * @short A communication session with the Akonadi storage. - * - * Every Job object has to be associated with a Session. - * The session is responsible of scheduling its jobs. - * For now only a simple serial execution is impleneted (the IMAP-like - * protocol to communicate with the storage backend is capable of parallel - * execution on a single session though). - * - * @code - * - * using namespace Akonadi; - * - * Session *session = new Session( "mySession" ); - * - * CollectionFetchJob *job = new CollectionFetchJob( Collection::root(), - * CollectionFetchJob::Recursive, - * session ); - * - * connect( job, SIGNAL( result( KJob* ) ), this, SLOT( slotResult( KJob* ) ) ); - * - * @endcode - * - * @author Volker Krause - */ -class AKONADI_EXPORT Session : public QObject -{ - Q_OBJECT - - friend class Job; - friend class JobPrivate; - friend class SessionPrivate; - - public: - /** - * Creates a new session. - * - * @param sessionId The identifier for this session, will be a - * random value if empty. - * @param parent The parent object. - * - * @see defaultSession() - */ - explicit Session( const QByteArray &sessionId = QByteArray(), QObject *parent = 0 ); - - /** - * Destroys the session. - */ - ~Session(); - - /** - * Returns the session identifier. - */ - QByteArray sessionId() const; - - /** - * Returns the default session for this thread. - */ - static Session* defaultSession(); - - /** - * Stops all jobs queued for execution. - */ - void clear(); - - private: - //@cond PRIVATE - SessionPrivate* const d; - - Q_PRIVATE_SLOT( d, void reconnect() ) - Q_PRIVATE_SLOT( d, void socketError() ) - Q_PRIVATE_SLOT( d, void dataReceived() ) - Q_PRIVATE_SLOT( d, void doStartNext() ) - Q_PRIVATE_SLOT( d, void jobDone( KJob* ) ) - Q_PRIVATE_SLOT( d, void jobWriteFinished( Akonadi::Job* ) ) - //@endcond PRIVATE -}; - -} - - -#endif diff --git a/akonadi/session_p.h b/akonadi/session_p.h deleted file mode 100644 index 22b138de2..000000000 --- a/akonadi/session_p.h +++ /dev/null @@ -1,109 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_SESSION_P_H -#define AKONADI_SESSION_P_H - -#include "session.h" -#include "imapparser_p.h" - -#include -#include -#include - -class QLocalSocket; - -namespace Akonadi { - -/** - * @internal - */ -class SessionPrivate -{ - public: - SessionPrivate( Session *parent ) - : mParent( parent ), mConnectionSettings( 0 ), protocolVersion( 0 ) - { - parser = new ImapParser(); - } - - ~SessionPrivate() - { - delete parser; - delete mConnectionSettings; - } - - void startNext(); - void reconnect(); - void socketError(); - void dataReceived(); - void doStartNext(); - void startJob( Job* job ); - void jobDone( KJob* job ); - void jobWriteFinished( Akonadi::Job* job ); - - bool canPipelineNext(); - - /** - * Creates a new default session for this thread with - * the given @p sessionId. The session can be accessed - * later by defaultSession(). - * - * You only need to call this method if you want that the - * default session has a special custom id, otherwise a random unique - * id is used automatically. - */ - static void createDefaultSession( const QByteArray &sessionId ); - - /** - Associates the given Job object with this session. - */ - void addJob( Job* job ); - - /** - Returns the next IMAP tag. - */ - int nextTag(); - - /** - Sends the given raw data. - */ - void writeData( const QByteArray &data ); - - Session *mParent; - QByteArray sessionId; - QSettings *mConnectionSettings; - QLocalSocket* socket; - bool connected; - int theNextTag; - int protocolVersion; - - // job management - QQueue queue; - QQueue pipeline; - Job* currentJob; - bool jobRunning; - - // parser stuff - ImapParser *parser; -}; - -} - -#endif diff --git a/akonadi/standardactionmanager.cpp b/akonadi/standardactionmanager.cpp deleted file mode 100644 index dcae60c31..000000000 --- a/akonadi/standardactionmanager.cpp +++ /dev/null @@ -1,388 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "standardactionmanager.h" - -#include "agentmanager.h" -#include "collectioncreatejob.h" -#include "collectiondeletejob.h" -#include "collectionmodel.h" -#include "collectionutils_p.h" -#include "collectionpropertiesdialog.h" -#include "itemdeletejob.h" -#include "itemmodel.h" -#include "pastehelper.h" -#include "subscriptiondialog.h" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include - -using namespace Akonadi; - -static const struct { - const char *name; - const char *label; - const char *icon; - int shortcut; - const char* slot; -} actionData[] = { - { "akonadi_collection_create", I18N_NOOP("&New Folder..."), "folder-new", 0, SLOT(slotCreateCollection()) }, - { "akonadi_collection_copy", 0, "edit-copy", 0, SLOT(slotCopyCollections()) }, - { "akonadi_collection_delete", I18N_NOOP("&Delete Folder"), "edit-delete", 0, SLOT(slotDeleteCollection()) }, - { "akonadi_collection_sync", I18N_NOOP("&Synchronize Folder"), "view-refresh", Qt::Key_F5, SLOT(slotSynchronizeCollection()) }, - { "akonadi_collection_properties", I18N_NOOP("Folder &Properties..."), "configure", 0, SLOT(slotCollectionProperties()) }, - { "akonadi_item_copy", 0, "edit-copy", 0, SLOT(slotCopyItems()) }, - { "akonadi_paste", I18N_NOOP("&Paste"), "edit-paste", Qt::CTRL + Qt::Key_V, SLOT(slotPaste()) }, - { "akonadi_item_delete", 0, "edit-delete", Qt::Key_Delete, SLOT(slotDeleteItems()) }, - { "akonadi_manage_local_subscriptions", I18N_NOOP("Manage Local &Subscriptions..."), 0, 0, SLOT(slotLocalSubscription()) } -}; -static const int numActionData = sizeof actionData / sizeof *actionData; - -BOOST_STATIC_ASSERT( numActionData == StandardActionManager::LastType ); - -static bool canCreateCollection( const Collection &collection ) -{ - if ( !( collection.rights() & Collection::CanCreateCollection ) ) - return false; - - if ( !collection.contentMimeTypes().contains( Collection::mimeType() ) ) - return false; - - return true; -} - -/** - * @internal - */ -class StandardActionManager::Private -{ - public: - Private( StandardActionManager *parent ) : - q( parent ), - collectionSelectionModel( 0 ), - itemSelectionModel( 0 ) - { - actions.fill( 0, StandardActionManager::LastType ); - - pluralLabels.insert( StandardActionManager::CopyCollections, ki18np( "&Copy Folder", "&Copy %1 Folders" ) ); - pluralLabels.insert( StandardActionManager::CopyItems, ki18np( "&Copy Item", "&Copy %1 Items" ) ); - pluralLabels.insert( StandardActionManager::DeleteItems, ki18np( "&Delete Item", "&Delete %1 Items" ) ); - } - - void enableAction( StandardActionManager::Type type, bool enable ) - { - Q_ASSERT( type >= 0 && type < StandardActionManager::LastType ); - if ( actions[type] ) - actions[type]->setEnabled( enable ); - } - - void updatePluralLabel( StandardActionManager::Type type, int count ) - { - Q_ASSERT( type >= 0 && type < StandardActionManager::LastType ); - if ( actions[type] && pluralLabels.contains( type ) && !pluralLabels.value( type ).isEmpty() ) { - actions[type]->setText( pluralLabels.value( type ).subs( qMax( count, 1 ) ).toString() ); - } - } - - void copy( QItemSelectionModel* selModel ) - { - Q_ASSERT( selModel ); - if ( selModel->selectedRows().count() <= 0 ) - return; - QMimeData *mimeData = selModel->model()->mimeData( selModel->selectedRows() ); - QApplication::clipboard()->setMimeData( mimeData ); - } - - void updateActions() - { - bool singleColSelected = false; - bool multiColSelected = false; - int colCount = 0; - QModelIndex selectedIndex; - if ( collectionSelectionModel ) { - colCount = collectionSelectionModel->selectedRows().count(); - singleColSelected = colCount == 1; - multiColSelected = colCount > 0; - if ( singleColSelected ) - selectedIndex = collectionSelectionModel->selectedRows().first(); - } - - enableAction( CopyCollections, multiColSelected ); - enableAction( CollectionProperties, singleColSelected ); - - if ( singleColSelected && selectedIndex.isValid() ) { - const Collection col = selectedIndex.data( CollectionModel::CollectionRole ).value(); - enableAction( CreateCollection, canCreateCollection( col ) ); - enableAction( DeleteCollections, col.rights() & Collection::CanDeleteCollection ); - enableAction( SynchronizeCollections, CollectionUtils::isResource( col ) || CollectionUtils::isFolder( col ) ); - enableAction( Paste, PasteHelper::canPaste( QApplication::clipboard()->mimeData(), col ) ); - } else { - enableAction( CreateCollection, false ); - enableAction( DeleteCollections, false ); - enableAction( SynchronizeCollections, false ); - enableAction( Paste, false ); - } - - bool multiItemSelected = false; - int itemCount = 0; - if ( itemSelectionModel ) { - itemCount = itemSelectionModel->selectedRows().count(); - multiItemSelected = itemCount > 0; - } - - enableAction( CopyItems, multiItemSelected ); - enableAction( DeleteItems, multiItemSelected ); - - updatePluralLabel( CopyCollections, colCount ); - updatePluralLabel( CopyItems, itemCount ); - updatePluralLabel( DeleteItems, itemCount ); - - emit q->actionStateUpdated(); - } - - void clipboardChanged( QClipboard::Mode mode ) - { - if ( mode == QClipboard::Clipboard ) - updateActions(); - } - - void slotCreateCollection() - { - const QModelIndex index = collectionSelectionModel->currentIndex(); - const Collection collection = index.data( CollectionModel::CollectionRole ).value(); - - if ( !canCreateCollection( collection ) ) - return; - - const QString name = KInputDialog::getText( i18nc( "@title:window", "New Folder"), - i18nc( "@label:textbox, name of a thing", "Name"), - QString(), 0, parentWidget ); - if ( name.isEmpty() ) - return; - Collection::Id parentId = index.data( CollectionModel::CollectionIdRole ).toLongLong(); - if ( parentId <= 0 ) - return; - - Collection col; - col.setName( name ); - col.setParent( parentId ); - CollectionCreateJob *job = new CollectionCreateJob( col ); - q->connect( job, SIGNAL(result(KJob*)), q, SLOT(collectionCreationResult(KJob*)) ); - } - - void slotCopyCollections() - { - copy( collectionSelectionModel ); - } - - void slotDeleteCollection() - { - Q_ASSERT( collectionSelectionModel ); - const QModelIndex index = collectionSelectionModel->currentIndex(); - if ( !index.isValid() ) - return; - - const Collection collection = index.data( CollectionModel::CollectionRole ).value(); - QString text = i18n( "Do you really want to delete folder '%1' and all its sub-folders?", index.data().toString() ); - if ( CollectionUtils::isVirtual( collection ) ) - text = i18n( "Do you really want to delete the search view '%1'?", index.data().toString() ); - - if ( KMessageBox::questionYesNo( parentWidget, text, - i18n("Delete folder?"), KStandardGuiItem::del(), KStandardGuiItem::cancel(), - QString(), KMessageBox::Dangerous ) != KMessageBox::Yes ) - return; - const Collection::Id colId = index.data( CollectionModel::CollectionIdRole ).toLongLong(); - if ( colId <= 0 ) - return; - - CollectionDeleteJob *job = new CollectionDeleteJob( Collection( colId ), q ); - q->connect( job, SIGNAL(result(KJob*)), q, SLOT(collectionDeletionResult(KJob*)) ); - } - - void slotSynchronizeCollection() - { - QModelIndex index = collectionSelectionModel->currentIndex(); - if ( !index.isValid() ) - return; - const Collection col = index.data( CollectionModel::CollectionRole ).value(); - AgentManager::self()->synchronizeCollection( col ); - } - - void slotCollectionProperties() - { - const QModelIndex index = collectionSelectionModel->currentIndex(); - if ( !index.isValid() ) - return; - const Collection col = index.data( CollectionModel::CollectionRole ).value(); - CollectionPropertiesDialog* dlg = new CollectionPropertiesDialog( col, parentWidget ); - dlg->show(); - } - - void slotCopyItems() - { - copy( itemSelectionModel ); - } - - void slotPaste() - { - const QModelIndex index = collectionSelectionModel->currentIndex(); - if ( !index.isValid() ) - return; - const Collection col = index.data( CollectionModel::CollectionRole ).value(); - KJob *job = PasteHelper::paste( QApplication::clipboard()->mimeData(), col ); - q->connect( job, SIGNAL(result(KJob*)), q, SLOT(pasteResult(KJob*)) ); - } - - void slotDeleteItems() - { - if ( KMessageBox::questionYesNo( parentWidget, - i18n( "Do you really want to delete all selected items?" ), - i18n("Delete?"), KStandardGuiItem::del(), KStandardGuiItem::cancel(), - QString(), KMessageBox::Dangerous ) != KMessageBox::Yes ) - return; - - Q_ASSERT( itemSelectionModel ); - - // TODO: fix this once ItemModifyJob can handle item lists - foreach ( const QModelIndex &index, itemSelectionModel->selectedRows() ) { - new ItemDeleteJob( Item( index.data( ItemModel::IdRole ).toLongLong() ), q ); - } - } - - void slotLocalSubscription() - { - SubscriptionDialog* dlg = new SubscriptionDialog( parentWidget ); - dlg->show(); - } - - void collectionCreationResult( KJob *job ) - { - if ( job->error() ) { - KMessageBox::error( parentWidget, i18n("Could not create folder: %1", job->errorString()), - i18n("Folder creation failed") ); - } - } - - void collectionDeletionResult( KJob *job ) - { - if ( job->error() ) { - KMessageBox::error( parentWidget, i18n("Could not delete folder: %1", job->errorString()), - i18n("Folder deletion failed") ); - } - } - - void pasteResult( KJob *job ) - { - if ( job->error() ) { - KMessageBox::error( parentWidget, i18n("Could not paste data: %1", job->errorString()), - i18n("Paste failed") ); - } - } - - StandardActionManager *q; - KActionCollection *actionCollection; - QWidget *parentWidget; - QItemSelectionModel *collectionSelectionModel; - QItemSelectionModel *itemSelectionModel; - QVector actions; - AgentManager *agentManager; - QHash pluralLabels; -}; - -StandardActionManager::StandardActionManager( KActionCollection * actionCollection, - QWidget * parent) : - QObject( parent ), - d( new Private( this ) ) -{ - d->parentWidget = parent; - d->actionCollection = actionCollection; - connect( QApplication::clipboard(), SIGNAL(changed(QClipboard::Mode)), SLOT(clipboardChanged(QClipboard::Mode)) ); -} - -StandardActionManager::~ StandardActionManager() -{ - delete d; -} - -void StandardActionManager::setCollectionSelectionModel(QItemSelectionModel * selectionModel) -{ - d->collectionSelectionModel = selectionModel; - connect( selectionModel, SIGNAL(selectionChanged( const QItemSelection&, const QItemSelection& )), - SLOT(updateActions()) ); -} - -void StandardActionManager::setItemSelectionModel(QItemSelectionModel * selectionModel) -{ - d->itemSelectionModel = selectionModel; - connect( selectionModel, SIGNAL(selectionChanged( const QItemSelection&, const QItemSelection& )), - SLOT(updateActions()) ); -} - -KAction* StandardActionManager::createAction( Type type ) -{ - Q_ASSERT( type >= 0 && type < LastType ); - Q_ASSERT( actionData[type].name ); - if ( d->actions[type] ) - return d->actions[type]; - KAction *action = new KAction( d->parentWidget ); - if ( d->pluralLabels.contains( type ) && !d->pluralLabels.value( type ).isEmpty() ) - action->setText( d->pluralLabels.value( type ).subs( 1 ).toString() ); - else if ( actionData[type].label ) - action->setText( i18n( actionData[type].label ) ); - if ( actionData[type].icon ) - action->setIcon( KIcon( QString::fromLatin1( actionData[type].icon ) ) ); - action->setShortcut( actionData[type].shortcut ); - if ( actionData[type].slot ) - connect( action, SIGNAL(triggered()), actionData[type].slot ); - d->actionCollection->addAction( QString::fromLatin1(actionData[type].name), action ); - d->actions[type] = action; - d->updateActions(); - return action; -} - -void StandardActionManager::createAllActions() -{ - for ( int i = 0; i < LastType; ++i ) - createAction( (Type)i ); -} - -KAction * StandardActionManager::action( Type type ) const -{ - Q_ASSERT( type >= 0 && type < LastType ); - return d->actions[type]; -} - -void StandardActionManager::setActionText(Type type, const KLocalizedString & text) -{ - Q_ASSERT( type >= 0 && type < LastType ); - d->pluralLabels.insert( type, text ); -} - -#include "standardactionmanager.moc" diff --git a/akonadi/standardactionmanager.h b/akonadi/standardactionmanager.h deleted file mode 100644 index 4a40234f6..000000000 --- a/akonadi/standardactionmanager.h +++ /dev/null @@ -1,201 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_STANDARDACTIONMANAGER_H -#define AKONADI_STANDARDACTIONMANAGER_H - -#include "akonadi_export.h" - -#include - -class KAction; -class KActionCollection; -class KLocalizedString; -class QItemSelectionModel; -class QWidget; - -namespace Akonadi { - -/** - * @short Manages generic actions for collection and item views. - * - * Manages generic Akonadi actions common for all types. This covers - * creating of the actions with appropriate labels, icons, shortcuts - * etc., updating the action state depending on the current selection - * as well as default implementations for the actual operations. - * - * If the default implementation is not appropriate for your application - * you can still use the state tracking by disconnecting the triggered() - * signal and re-connecting it to your implementation. The actual KAction - * objects can be retrieved by calling createAction() or action() for that. - * - * If the default look and feel (labels, icons, shortcuts) of the actions - * is not appropriate for your application, you can access them as noted - * above and customize them to your needs. Additionally, you can set a - * KLocalizedString which should be used as a action label with correct - * plural handling for actions operating on multiple objects with - * setActionText(). - * - * Finally, if you have special needs for the action states, connect to - * the actionStateUpdated() signal and adjust the state accordingly. - * - * The following actions are provided (KAction name in parenthesis): - * - Creation of a new collection (@c akonadi_collection_create) - * - Copying of selected collections (@c akonadi_collection_copy) - * - Deletion of selected collections (@c akonadi_collection_delete) - * - Synchronization of selected collections (@c akonadi_collection_sync) - * - Showing the collection properties dialog for the current collection (@c akonadi_collection_properties) - * - Copying of selected items (@c akonadi_itemcopy) - * - Pasting collections, items or raw data (@c akonadi_paste) - * - Deleting of selected items (@c akonadi_item_delete) - * - Managing local subscriptions (@c akonadi_manage_local_subscriptions) - * - * The following example shows how to use standard actions in your application: - * - * @code - * - * Akonadi::StandardActionManager *actMgr = new Akonadi::StandardActionManager( actionCollection(), this ); - * actMgr->setCollectionSelectionModel( collectionView->collectionSelectionModel() ); - * actMgr->createAllActions(); - * - * @endcode - * - * Additionally you have to add the actions to the KXMLGUI file of your application, - * using the names listed above. - * - * If you only need a subset of the actions provided, you can call createAction() - * instead of createAllActions() for the action types you want. - * - * @todo collection deleting and sync do not support multi-selection yet - * - * @author Volker Krause - */ -class AKONADI_EXPORT StandardActionManager : public QObject -{ - Q_OBJECT - public: - /** - * Describes the supported actions. - */ - enum Type { - CreateCollection, ///< Creates an collection - CopyCollections, ///< Copies collections - DeleteCollections, ///< Deletes collections - SynchronizeCollections, ///< Synchronizes collections - CollectionProperties, ///< Provides collection properties - CopyItems, ///< Copies items - Paste, ///< Paste collections or items - DeleteItems, ///< Deletes items - ManageLocalSubscriptions, ///< Manages local subscriptions - LastType ///< Marks last action - }; - - /** - * Creates a new standard action manager. - * - * @param actionCollection The action collection to operate on. - * @param parent The parent widget. - */ - explicit StandardActionManager( KActionCollection *actionCollection, QWidget *parent = 0 ); - - /** - * Destroys the standard action manager. - */ - ~StandardActionManager(); - - /** - * Sets the collection selection model based on which the collection - * related actions should operate. If none is set, all collection actions - * will be disabled. - */ - void setCollectionSelectionModel( QItemSelectionModel *selectionModel ); - - /** - * Sets the item selection model based on which the item related actions - * should operate. If none is set, all item actions will be disabled. - */ - void setItemSelectionModel( QItemSelectionModel* selectionModel ); - - /** - * Creates the action of the given type and adds it to the action collection - * specified in the constructor if it does not exist yet. The action is - * connected to its default implementation provided by this class. - */ - KAction* createAction( Type type ); - - /** - * Convenience method to create all standard actions. - * @see createAction() - */ - void createAllActions(); - - /** - * Returns the action of the given type, 0 if it has not been created (yet). - */ - KAction* action( Type type ) const; - - /** - * Sets the label of the action @p type to @p text, which is used during - * updating the action state and substituted according to the number of - * selected objects. This is mainly useful to customize the label of actions - * that can operate on multiple objects. - * - * Example: - * @code - * acctMgr->setActionText( Akonadi::StandardActionManager::CopyItems, - * ki18np( "Copy Mail", "Copy %1 Mails" ) ); - * @endcode - */ - void setActionText( Type type, const KLocalizedString &text ); - - Q_SIGNALS: - /** - * This signal is emitted whenever the action state has been updated. - * In case you have special needs for changing the state of some actions, - * connect to this signal and adjust the action state. - */ - void actionStateUpdated(); - - private: - //@cond PRIVATE - class Private; - Private* const d; - - Q_PRIVATE_SLOT( d, void updateActions() ) - Q_PRIVATE_SLOT( d, void clipboardChanged(QClipboard::Mode) ) - - Q_PRIVATE_SLOT( d, void slotCreateCollection() ) - Q_PRIVATE_SLOT( d, void slotCopyCollections() ) - Q_PRIVATE_SLOT( d, void slotDeleteCollection() ) - Q_PRIVATE_SLOT( d, void slotSynchronizeCollection() ) - Q_PRIVATE_SLOT( d, void slotCollectionProperties() ) - Q_PRIVATE_SLOT( d, void slotCopyItems() ) - Q_PRIVATE_SLOT( d, void slotPaste() ) - Q_PRIVATE_SLOT( d, void slotDeleteItems() ) - Q_PRIVATE_SLOT( d, void slotLocalSubscription() ) - - Q_PRIVATE_SLOT( d, void collectionCreationResult(KJob*) ) - Q_PRIVATE_SLOT( d, void collectionDeletionResult(KJob*) ) - Q_PRIVATE_SLOT( d, void pasteResult(KJob*) ) - //@endcond -}; - -} - -#endif diff --git a/akonadi/subscriptionchangeproxymodel.cpp b/akonadi/subscriptionchangeproxymodel.cpp deleted file mode 100644 index fb04b1563..000000000 --- a/akonadi/subscriptionchangeproxymodel.cpp +++ /dev/null @@ -1,78 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "subscriptionchangeproxymodel.h" -#include "subscriptionmodel.h" - -#include -#include - -using namespace Akonadi; - -/** - * @internal - */ -class SubscriptionChangeProxyModel::Private -{ - public: - Qt::CheckState subscribed; -}; - -SubscriptionChangeProxyModel::SubscriptionChangeProxyModel(bool subscribed, QObject * parent) : - QSortFilterProxyModel( parent ), - d( new Private ) -{ - d->subscribed = subscribed ? Qt::Checked : Qt::Unchecked; - setDynamicSortFilter( true ); -} - -SubscriptionChangeProxyModel::~ SubscriptionChangeProxyModel() -{ - delete d; -} - -bool SubscriptionChangeProxyModel::filterAcceptsRow(int row, const QModelIndex & parent) const -{ - QModelIndex index = sourceModel()->index( row, 0, parent ); - if ( !index.data( SubscriptionModel::SubscriptionChangedRole ).toBool() ) - return false; - if ( index.data( Qt::CheckStateRole ) != d->subscribed ) - return false; - return true; -} - -QVariant SubscriptionChangeProxyModel::data(const QModelIndex & index, int role) const -{ - if ( role == Qt::CheckStateRole ) - return QVariant(); - return QSortFilterProxyModel::data( index, role ); -} - -QVariant SubscriptionChangeProxyModel::headerData(int section, Qt::Orientation orientation, int role) const -{ - if ( section == 0 && orientation == Qt::Horizontal && role == Qt::DisplayRole ) { - if ( d->subscribed == Qt::Checked ) - return i18nc( "@title:column", "Subscribe To" ); - else - return i18nc( "@title:column", "Unsubscribe From" ); - } - return QSortFilterProxyModel::headerData( section, orientation, role ); -} - -#include "subscriptionchangeproxymodel.moc" diff --git a/akonadi/subscriptionchangeproxymodel.h b/akonadi/subscriptionchangeproxymodel.h deleted file mode 100644 index 1b34fb088..000000000 --- a/akonadi/subscriptionchangeproxymodel.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_SUBSCRIPTIONCHANGEPROXYMODEL_H -#define AKONADI_SUBSCRIPTIONCHANGEPROXYMODEL_H - -#include - -namespace Akonadi { - -/** - * @internal - * - * Proxy model that can be used on top of a SubscriptionModel to filter out - * only the actual changes. - */ -class SubscriptionChangeProxyModel : public QSortFilterProxyModel -{ - Q_OBJECT - public: - /** - Create a new subscription change proxy model. - @param subscribed @c true to list only newly subscribed collections, @c false to - list only newly unsubscribed collections. - @param parent The parent object. - */ - explicit SubscriptionChangeProxyModel( bool subscribed, QObject *parent = 0 ); - - /** - Destructor. - */ - ~SubscriptionChangeProxyModel(); - - QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) const; - QVariant headerData( int section, Qt::Orientation orientation, int role = Qt::DisplayRole ) const; - - protected: - bool filterAcceptsRow( int row, const QModelIndex &parent ) const; - - private: - class Private; - Private* const d; -}; - -} - -#endif diff --git a/akonadi/subscriptiondialog.cpp b/akonadi/subscriptiondialog.cpp deleted file mode 100644 index 40710e281..000000000 --- a/akonadi/subscriptiondialog.cpp +++ /dev/null @@ -1,124 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "subscriptiondialog.h" -#include "ui_subscriptiondialog.h" -#include "subscriptionmodel.h" -#include "subscriptionjob.h" -#include "subscriptionchangeproxymodel.h" -#include "flatcollectionproxymodel.h" - -#include - -using namespace Akonadi; - -/** - * @internal - */ -class SubscriptionDialog::Private -{ - public: - Private( SubscriptionDialog *parent ) : q( parent ) {} - - void setupChangeView( QTreeView *view, bool subscribe ) - { - FlatCollectionProxyModel *flatProxy = new FlatCollectionProxyModel( q ); - flatProxy->setSourceModel( model ); - SubscriptionChangeProxyModel *subProxy = new SubscriptionChangeProxyModel( subscribe, q ); - subProxy->setSourceModel( flatProxy ); - view->setModel( subProxy ); - } - - void done() - { - SubscriptionJob *job = new SubscriptionJob( q ); - job->subscribe( model->subscribed() ); - job->unsubscribe( model->unsubscribed() ); - connect( job, SIGNAL(result(KJob*)), q, SLOT(subscriptionResult(KJob*)) ); - } - - void subscriptionResult( KJob *job ) - { - if ( job->error() ) { - // TODO - kWarning() << job->errorString(); - } - q->deleteLater(); - } - - void subscribeClicked() - { - foreach( const QModelIndex &index, ui.collectionView->selectionModel()->selectedIndexes() ) - model->setData( index, Qt::Checked, Qt::CheckStateRole ); - } - - void unsubscribeClicked() - { - foreach( const QModelIndex &index, ui.collectionView->selectionModel()->selectedIndexes() ) - model->setData( index, Qt::Unchecked, Qt::CheckStateRole ); - } - - void modelLoaded() - { - ui.collectionView->setEnabled( true ); - ui.subscribeButton->setEnabled( true ); - ui.unsubscribeButton->setEnabled( true ); - ui.subscribeView->setEnabled( true ); - ui.unsubscribeView->setEnabled( true ); - q->enableButtonOk( true ); - } - - SubscriptionDialog* q; - Ui::SubscriptionDialog ui; - SubscriptionModel* model; -}; - -SubscriptionDialog::SubscriptionDialog(QWidget * parent) : - KDialog( parent ), - d( new Private( this ) ) -{ - enableButtonOk( false ); - d->ui.setupUi( mainWidget() ); - KIcon icon; - if ( QApplication::isLeftToRight() ) - icon = KIcon( QLatin1String("go-next") ); - else - icon = KIcon( QLatin1String("go-previous") ); - d->ui.subscribeButton->setIcon( icon ); - d->ui.unsubscribeButton->setIcon( icon ); - - d->model = new SubscriptionModel( this ); - d->ui.collectionView->setModel( d->model ); - - d->setupChangeView( d->ui.subscribeView, true ); - d->setupChangeView( d->ui.unsubscribeView, false ); - - connect( d->model, SIGNAL(loaded()), SLOT(modelLoaded()) ); - connect( d->ui.subscribeButton, SIGNAL(clicked()), SLOT(subscribeClicked()) ); - connect( d->ui.unsubscribeButton, SIGNAL(clicked()), SLOT(unsubscribeClicked()) ); - connect( this, SIGNAL(okClicked()), SLOT(done()) ); - connect( this, SIGNAL(cancelClicked()), SLOT(deleteLater()) ); -} - -SubscriptionDialog::~ SubscriptionDialog() -{ - delete d; -} - -#include "subscriptiondialog.moc" diff --git a/akonadi/subscriptiondialog.h b/akonadi/subscriptiondialog.h deleted file mode 100644 index c37013cfe..000000000 --- a/akonadi/subscriptiondialog.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_SUBSCRIPTIONDIALOG_H -#define AKONADI_SUBSCRIPTIONDIALOG_H - -#include "akonadi_export.h" - -#include - -namespace Akonadi { - -/** - * @internal - * - * Local subsription dialog. - */ -class AKONADI_EXPORT SubscriptionDialog : public KDialog -{ - Q_OBJECT - public: - /** - Create a new subscription dialog. - @param parent The parent widget. - */ - explicit SubscriptionDialog( QWidget *parent = 0 ); - - /** - Destructor, don't call manually. The dialog will be destructed automatically - as soon as all changes are written back to the server. - */ - ~SubscriptionDialog(); - - private: - class Private; - Private* const d; - Q_PRIVATE_SLOT( d, void done() ) - Q_PRIVATE_SLOT( d, void subscriptionResult( KJob* job ) ) - Q_PRIVATE_SLOT( d, void subscribeClicked() ) - Q_PRIVATE_SLOT( d, void unsubscribeClicked() ) - Q_PRIVATE_SLOT( d, void modelLoaded() ) -}; - -} - -#endif diff --git a/akonadi/subscriptiondialog.ui b/akonadi/subscriptiondialog.ui deleted file mode 100644 index 4292d8b25..000000000 --- a/akonadi/subscriptiondialog.ui +++ /dev/null @@ -1,161 +0,0 @@ - - Volker Krause <vkrause@kde.org> - SubscriptionDialog - - - - 0 - 0 - 686 - 525 - - - - - - - Manage which folders you want to see in the folder tree - - - - - - - - - Search: - - - klineedit - - - - - - - false - - - TODO - - - true - - - - - - - - - <b>Available folders</b> - - - - - - - Qt::Horizontal - - - - 151 - 20 - - - - - - - - <b>Current changes</b> - - - - - - - Qt::Horizontal - - - - 151 - 20 - - - - - - - - false - - - QAbstractItemView::NoEditTriggers - - - - - - - false - - - Subscribe to selected folder - - - - - - - false - - - QAbstractItemView::NoEditTriggers - - - false - - - - - - - false - - - Unsubscribe from selected folder - - - - - - - false - - - QAbstractItemView::NoEditTriggers - - - false - - - - - - - - KLineEdit - QLineEdit -
klineedit.h
-
- - KPushButton - QPushButton -
kpushbutton.h
-
-
- - - -
diff --git a/akonadi/subscriptionjob.cpp b/akonadi/subscriptionjob.cpp deleted file mode 100644 index 659c7381a..000000000 --- a/akonadi/subscriptionjob.cpp +++ /dev/null @@ -1,115 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "subscriptionjob.h" - -#include "job_p.h" - -using namespace Akonadi; - -class Akonadi::SubscriptionJobPrivate : public JobPrivate -{ - public: - SubscriptionJobPrivate( SubscriptionJob *parent ) - : JobPrivate( parent ) - { - } - - void sendCommand( const QByteArray &cmd, const Collection::List &list ) - { - Q_Q( SubscriptionJob ); - - mTag = newTag(); - QByteArray line = mTag + ' ' + cmd; - foreach ( const Collection &col, list ) - line += ' ' + QByteArray::number( col.id() ); - line += '\n'; - writeData( line ); - newTag(); // prevent automatic response handling - } - - void sendNextCommand() - { - Q_Q( SubscriptionJob ); - - QByteArray cmd; - if ( !mSub.isEmpty() ) { - sendCommand( "SUBSCRIBE", mSub ); - mSub.clear(); - } else if ( !mUnsub.isEmpty() ) { - sendCommand( "UNSUBSCRIBE", mUnsub ); - mUnsub.clear(); - } else { - q->emitResult(); - } - } - - Q_DECLARE_PUBLIC( SubscriptionJob ) - - QByteArray mTag; - Collection::List mSub, mUnsub; -}; - -SubscriptionJob::SubscriptionJob(QObject * parent) - : Job( new SubscriptionJobPrivate( this ), parent ) -{ -} - -SubscriptionJob::~SubscriptionJob() -{ -} - -void SubscriptionJob::subscribe(const Collection::List & list) -{ - Q_D( SubscriptionJob ); - - d->mSub = list; -} - -void SubscriptionJob::unsubscribe(const Collection::List & list) -{ - Q_D( SubscriptionJob ); - - d->mUnsub = list; -} - -void SubscriptionJob::doStart() -{ - Q_D( SubscriptionJob ); - - d->sendNextCommand(); -} - -void SubscriptionJob::doHandleResponse(const QByteArray &_tag, const QByteArray & data) -{ - Q_D( SubscriptionJob ); - - if ( _tag == d->mTag ) { - if ( data.startsWith( "OK" ) ) { - d->sendNextCommand(); - } else { - setError( Unknown ); - setErrorText( QString::fromUtf8( data ) ); - emitResult(); - } - return; - } -} - -#include "subscriptionjob.moc" diff --git a/akonadi/subscriptionjob.h b/akonadi/subscriptionjob.h deleted file mode 100644 index 5d0a74cbf..000000000 --- a/akonadi/subscriptionjob.h +++ /dev/null @@ -1,72 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_SUBSCRIPTIONJOB_H -#define AKONADI_SUBSCRIPTIONJOB_H - -#include -#include - -namespace Akonadi { - -class SubscriptionJobPrivate; - -/** - * @internal - * - * Job to manipulate the local subscription state of a set of collections. - */ -class AKONADI_EXPORT SubscriptionJob : public Job -{ - Q_OBJECT - public: - /** - Create a new subscription job. - @param parent The parent object. - */ - explicit SubscriptionJob( QObject *parent = 0 ); - - /** - Destroys this job. - */ - ~SubscriptionJob(); - - /** - Subscribe to the given list of collections. - @param list List of collections to subscribe to. - */ - void subscribe( const Collection::List &list ); - - /** - Unsubscribe from the given list of collections. - @param list List of collections to unsubscribe from. - */ - void unsubscribe( const Collection::List &list ); - - protected: - void doStart(); - void doHandleResponse( const QByteArray &tag, const QByteArray &data ); - - private: - Q_DECLARE_PRIVATE( SubscriptionJob ) -}; - -} - -#endif diff --git a/akonadi/subscriptionmodel.cpp b/akonadi/subscriptionmodel.cpp deleted file mode 100644 index 813c27541..000000000 --- a/akonadi/subscriptionmodel.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "subscriptionmodel.h" -#include "collectionfetchjob.h" -#include "collectionutils_p.h" - -#include - -#include - -using namespace Akonadi; - -/** - * @internal - */ -class SubscriptionModel::Private -{ - public: - Private( SubscriptionModel* parent ) : q( parent ) {} - SubscriptionModel* q; - QHash subscriptions; - QSet changes; - - Collection::List changedSubscriptions( bool subscribed ) - { - Collection::List list; - foreach ( Collection::Id id, changes ) { - if ( subscriptions.value( id ) == subscribed ) - list << Collection( id ); - } - return list; - } - - void listResult( KJob* job ) - { - if ( job->error() ) { - // TODO - kWarning() << job->errorString(); - return; - } - Collection::List cols = static_cast( job )->collections(); - foreach( const Collection &col, cols ) - if ( !CollectionUtils::isStructural( col ) ) - subscriptions[ col.id() ] = true; - q->reset(); - emit q->loaded(); - } - - bool isSubscribable( Collection::Id id ) - { - Collection col = q->collectionForId( id ); - if ( CollectionUtils::isVirtualParent( col ) || CollectionUtils::isStructural( col ) ) - return false; - if ( col.contentMimeTypes().isEmpty() ) - return false; - return true; - } -}; - -SubscriptionModel::SubscriptionModel(QObject * parent) : - CollectionModel( parent ), - d( new Private( this ) ) -{ - includeUnsubscribed(); - CollectionFetchJob* job = new CollectionFetchJob( Collection::root(), CollectionFetchJob::Recursive, this ); - connect( job, SIGNAL(result(KJob*)), this, SLOT(listResult(KJob*)) ); -} - -SubscriptionModel::~ SubscriptionModel() -{ - delete d; -} - -QVariant SubscriptionModel::data(const QModelIndex & index, int role) const -{ - switch ( role ) { - case Qt::CheckStateRole: - { - const Collection::Id col = index.data( CollectionIdRole ).toLongLong(); - if ( !d->isSubscribable( col ) ) - return QVariant(); - if ( d->subscriptions.value( col ) ) - return Qt::Checked; - return Qt::Unchecked; - } - case SubscriptionChangedRole: - { - const Collection::Id col = index.data( CollectionIdRole ).toLongLong(); - if ( d->changes.contains( col ) ) - return true; - return false; - } - } - return CollectionModel::data( index, role ); -} - -Qt::ItemFlags SubscriptionModel::flags(const QModelIndex & index) const -{ - Qt::ItemFlags flags = CollectionModel::flags( index ); - if ( d->isSubscribable( index.data( CollectionIdRole ).toLongLong() ) ) - return flags | Qt::ItemIsUserCheckable; - return flags; -} - -bool SubscriptionModel::setData(const QModelIndex & index, const QVariant & value, int role) -{ - if ( role == Qt::CheckStateRole ) { - const Collection::Id col = index.data( CollectionIdRole ).toLongLong(); - if ( d->subscriptions.contains( col ) && d->subscriptions.value( col ) == (value == Qt::Checked) ) - return true; // no change - d->subscriptions[ col ] = value == Qt::Checked; - if ( d->changes.contains( col ) ) - d->changes.remove( col ); - else - d->changes.insert( col ); - emit dataChanged( index, index ); - return true; - } - return CollectionModel::setData( index, value, role ); -} - -Collection::List SubscriptionModel::subscribed() const -{ - return d->changedSubscriptions( true ); -} - -Collection::List SubscriptionModel::unsubscribed() const -{ - return d->changedSubscriptions( false ); -} - -#include "subscriptionmodel.moc" diff --git a/akonadi/subscriptionmodel.h b/akonadi/subscriptionmodel.h deleted file mode 100644 index 87f859828..000000000 --- a/akonadi/subscriptionmodel.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_SUBSCRIPTIONMODEL_H -#define AKONADI_SUBSCRIPTIONMODEL_H - -#include -#include - -namespace Akonadi { - -/** - * @internal - * - * An extended collection model used for the subscription dialog. - */ -class SubscriptionModel : public CollectionModel -{ - Q_OBJECT - public: - /** Additional roles. */ - enum Roles { - SubscriptionChangedRole = CollectionModel::UserRole + 1 ///< Indicate the subscription status has been changed. - }; - - /** - Create a new subscription model. - @param parent The parent object. - */ - explicit SubscriptionModel( QObject *parent = 0 ); - - /** - Destructor. - */ - ~SubscriptionModel(); - - QVariant data( const QModelIndex & index, int role = Qt::DisplayRole ) const; - Qt::ItemFlags flags( const QModelIndex &index ) const; - bool setData( const QModelIndex &index, const QVariant &value, int role = Qt::EditRole ); - - Collection::List subscribed() const; - Collection::List unsubscribed() const; - - signals: - /** - Emitted when the collection model is fully loaded. - */ - void loaded(); - - private: - class Private; - Private* const d; - Q_PRIVATE_SLOT( d, void listResult(KJob*) ) -}; - -} - -#endif diff --git a/akonadi/tests/CMakeLists.txt b/akonadi/tests/CMakeLists.txt deleted file mode 100644 index 7c3819859..000000000 --- a/akonadi/tests/CMakeLists.txt +++ /dev/null @@ -1,63 +0,0 @@ -set( EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_BINARY_DIR} ) - -set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${KDE4_ENABLE_EXCEPTIONS}" ) - -include_directories( - ${CMAKE_SOURCE_DIR}/akonadi - ${CMAKE_CURRENT_SOURCE_DIR}/../ - ${CMAKE_CURRENT_SOURCE_DIR} - ${Boost_INCLUDE_DIR} - ${AKONADI_INCLUDE_DIR} -) - -# convenience macro to add akonadi demo application -macro(add_akonadi_demo _source) - set(_test ${_source}) - get_filename_component(_name ${_source} NAME_WE) - kde4_add_executable(${_name} TEST ${_test}) - target_link_libraries(${_name} akonadi-kde akonadi-kmime) -endmacro(add_akonadi_demo) - - -# convenience macro to add akonadi qtestlib unit-tests -macro(add_akonadi_test _source) - set(_test ${_source}) - get_filename_component(_name ${_source} NAME_WE) - kde4_add_unit_test(${_name} TESTNAME libakonadi-${_name} ${_test}) - target_link_libraries(${_name} akonadi-kde akonadi-kmime ${QT_QTTEST_LIBRARY}) -endmacro(add_akonadi_test) - -# demo applications -add_akonadi_demo(itemdumper.cpp) -add_akonadi_demo(collectioncreator.cpp) -add_akonadi_demo(subscriber.cpp) -add_akonadi_demo(benchmarker.cpp) -target_link_libraries(benchmarker akonadi-kde ${QT_QTTEST_LIBRARY}) -add_akonadi_demo(headfetcher.cpp) -add_akonadi_demo(agentinstancewidgettest.cpp) -add_akonadi_demo(agenttypewidgettest.cpp) -add_akonadi_demo(pluginloadertest.cpp) - -# qtestlib unit tests -add_akonadi_test(imapparsertest.cpp) -add_akonadi_test(imapsettest.cpp) -add_akonadi_test(collectionjobtest.cpp) -add_akonadi_test(collectionpathresolvertest.cpp) -add_akonadi_test(collectionattributetest.cpp) -add_akonadi_test(itemfetchtest.cpp) -add_akonadi_test(itemhydratest.cpp) -add_akonadi_test(itemappendtest.cpp) -add_akonadi_test(itemstoretest.cpp) -add_akonadi_test(monitortest.cpp) -add_akonadi_test(searchjobtest.cpp) -add_akonadi_test(notificationmessagetest.cpp) -add_akonadi_test(itemtest.cpp) -add_akonadi_test(changerecordertest.cpp) -add_akonadi_test(resourcetest.cpp) -add_akonadi_test(subscriptiontest.cpp) -add_akonadi_test(transactiontest.cpp) -add_akonadi_test(itemcopytest.cpp) -add_akonadi_test(collectioncopytest.cpp) -add_akonadi_test(itemserializertest.cpp) -add_akonadi_test(itemsynctest.cpp) - diff --git a/akonadi/tests/agentinstancewidgettest.cpp b/akonadi/tests/agentinstancewidgettest.cpp deleted file mode 100644 index a6c6de086..000000000 --- a/akonadi/tests/agentinstancewidgettest.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* - Copyright (c) 2006-2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "agentinstance.h" -#include "agentinstancewidgettest.h" - -#include - -#include -#include -#include -#include - -Dialog::Dialog( QWidget *parent ) - : QDialog( parent ) -{ - QVBoxLayout *layout = new QVBoxLayout( this ); - - mWidget = new Akonadi::AgentInstanceWidget( this ); - connect( mWidget, SIGNAL( currentChanged( const Akonadi::AgentInstance&, const Akonadi::AgentInstance& ) ), - this, SLOT( currentChanged( const Akonadi::AgentInstance&, const Akonadi::AgentInstance& ) ) ); - - QDialogButtonBox *box = new QDialogButtonBox( this ); - - layout->addWidget( mWidget ); - layout->addWidget( box ); - - QPushButton *ok = box->addButton( QDialogButtonBox::Ok ); - connect( ok, SIGNAL( clicked() ), this, SLOT( accept() ) ); - - resize( 450, 320 ); -} - -void Dialog::done( int r ) -{ - if ( r == Accepted ) { - qDebug( "'%s' selected", qPrintable( mWidget->currentAgentInstance().identifier() ) ); - } - - QDialog::done( r ); -} - -void Dialog::currentChanged( const Akonadi::AgentInstance ¤t, const Akonadi::AgentInstance &previous ) -{ - qDebug( "current changed: %s -> %s", qPrintable( previous.identifier() ), qPrintable( current.identifier() ) ); -} - -int main( int argc, char **argv ) -{ - QApplication app( argc, argv ); - KComponentData kcd( "agentinstanceviewtest" ); - - Dialog dlg; - dlg.exec(); - - return 0; -} - -#include "agentinstancewidgettest.moc" diff --git a/akonadi/tests/agentinstancewidgettest.h b/akonadi/tests/agentinstancewidgettest.h deleted file mode 100644 index 627a7b9c5..000000000 --- a/akonadi/tests/agentinstancewidgettest.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - Copyright (c) 2006-2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AGENTINSTANCEWIDGETTEST_H -#define AGENTINSTANCEWIDGETTEST_H - -#include - -#include "agentinstancewidget.h" - -class Dialog : public QDialog -{ - Q_OBJECT - - public: - Dialog( QWidget *parent = 0 ); - - virtual void done( int ); - - private Q_SLOTS: - void currentChanged( const Akonadi::AgentInstance&, const Akonadi::AgentInstance& ); - - private: - Akonadi::AgentInstanceWidget *mWidget; -}; - -#endif diff --git a/akonadi/tests/agenttypewidgettest.cpp b/akonadi/tests/agenttypewidgettest.cpp deleted file mode 100644 index 1f3046e2f..000000000 --- a/akonadi/tests/agenttypewidgettest.cpp +++ /dev/null @@ -1,96 +0,0 @@ -/* - Copyright (c) 2006-2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "agenttype.h" -#include "agenttypewidgettest.h" -#include - -#include - -#include -#include -#include -#include -#include - -Dialog::Dialog( QWidget *parent ) - : QDialog( parent ) -{ - QVBoxLayout *layout = new QVBoxLayout( this ); - - mFilter = new QComboBox( this ); - mFilter->addItem( "None" ); - mFilter->addItem( "text/calendar" ); - mFilter->addItem( "text/directory" ); - mFilter->addItem( "message/rfc822" ); - connect( mFilter, SIGNAL( activated( int ) ), - this, SLOT( filterChanged( int ) ) ); - - mWidget = new Akonadi::AgentTypeWidget( this ); - connect( mWidget, SIGNAL( currentChanged( const Akonadi::AgentType&, const Akonadi::AgentType& ) ), - this, SLOT( currentChanged( const Akonadi::AgentType&, const Akonadi::AgentType& ) ) ); - - QDialogButtonBox *box = new QDialogButtonBox( this ); - - layout->addWidget( mFilter ); - layout->addWidget( mWidget ); - layout->addWidget( box ); - - QPushButton *ok = box->addButton( QDialogButtonBox::Ok ); - connect( ok, SIGNAL( clicked() ), this, SLOT( accept() ) ); - - QPushButton *cancel = box->addButton( QDialogButtonBox::Cancel ); - connect( cancel, SIGNAL( clicked() ), this, SLOT( reject() ) ); - - resize( 450, 320 ); -} - -void Dialog::done( int r ) -{ - if ( r == Accepted ) { - qDebug( "'%s' selected", qPrintable( mWidget->currentAgentType().identifier() ) ); - } - - QDialog::done( r ); -} - -void Dialog::currentChanged( const Akonadi::AgentType ¤t, const Akonadi::AgentType &previous ) -{ - qDebug( "current changed: %s -> %s", qPrintable( previous.identifier() ), qPrintable( current.identifier() ) ); -} - -void Dialog::filterChanged( int index ) -{ - mWidget->agentFilterProxyModel()->clearFilters(); - if ( index > 0 ) - mWidget->agentFilterProxyModel()->addMimeTypeFilter( mFilter->itemText( index ) ); -} - -int main( int argc, char **argv ) -{ - QApplication app( argc, argv ); - KComponentData kcd( "agenttypeviewtest" ); - - Dialog dlg; - dlg.exec(); - - return 0; -} - -#include "agenttypewidgettest.moc" diff --git a/akonadi/tests/agenttypewidgettest.h b/akonadi/tests/agenttypewidgettest.h deleted file mode 100644 index 74d14ecab..000000000 --- a/akonadi/tests/agenttypewidgettest.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - Copyright (c) 2006-2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AGENTTYPEWIDGETTEST_H -#define AGENTTYPEWIDGETTEST_H - -#include - -#include "agenttypewidget.h" - -class QComboBox; - -class Dialog : public QDialog -{ - Q_OBJECT - - public: - Dialog( QWidget *parent = 0 ); - - virtual void done( int ); - - private Q_SLOTS: - void currentChanged( const Akonadi::AgentType&, const Akonadi::AgentType& ); - void filterChanged( int ); - - private: - Akonadi::AgentTypeWidget *mWidget; - QComboBox *mFilter; -}; - -#endif diff --git a/akonadi/tests/benchmarker.cpp b/akonadi/tests/benchmarker.cpp deleted file mode 100644 index 2f5426e01..000000000 --- a/akonadi/tests/benchmarker.cpp +++ /dev/null @@ -1,262 +0,0 @@ -/* - Copyright (c) 2007 Robert Zwerus - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "benchmarker.h" -#include "collectionpathresolver_p.h" -#include "kmime/messageparts.h" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include - -#include - -#define WAIT_TIME 100 - -typedef boost::shared_ptr MessagePtr; - -using namespace Akonadi; - -BenchMarker::BenchMarker( const QString &maildir ) -{ - connect( AgentManager::self(), SIGNAL( instanceRemoved( const Akonadi::AgentInstance& ) ), - this, SLOT( instanceRemoved( const Akonadi::AgentInstance& ) ) ); - connect( AgentManager::self(), SIGNAL( instanceStatusChanged( const Akonadi::AgentInstance& ) ), - this, SLOT( instanceStatusChanged( const Akonadi::AgentInstance& ) ) ); - - output( "# Description\t\tAccount name\t\tTime\n" ); - - qDebug() << "Benchmarking maildir" << maildir; - currentAccount = maildir; - testMaildir( maildir ); - - qDebug() << "All done."; - QTimer::singleShot( 1000, this, SLOT( stop() ) ); -} - -void BenchMarker::stop() -{ - qApp->quit(); -} - -AgentInstance BenchMarker::createAgent( const QString &name ) -{ - const AgentType type = AgentManager::self()->type( name ); - - AgentInstanceCreateJob *job = new AgentInstanceCreateJob( type ); - job->exec(); - const AgentInstance instance = job->instance(); - - if( job->error() || !instance.isValid() ) { - qDebug() << " Unable to create resource" << name; - exit( -1 ); - } - else - qDebug() << " Created resource instance" << instance.identifier(); - - return instance; -} - -void BenchMarker::instanceRemoved( const AgentInstance &instance ) -{ - Q_UNUSED( instance ); - done = true; - // qDebug() << "agent removed:" << instance; -} - -void BenchMarker::instanceStatusChanged( const AgentInstance &instance ) -{ - //qDebug() << "agent status changed:" << agentIdentifier << status << message ; - if ( instance == currentInstance ) { - if ( instance.status() == AgentInstance::Running ) { - //qDebug() << " " << message; - } - if ( instance.status() == AgentInstance::Idle ) { - done = true; - } - } -} - -void BenchMarker::outputStats( const QString &description ) -{ - output( description + "\t\t" + currentAccount + "\t\t" + QByteArray::number( timer.elapsed() ) + '\n' ); -} - -void BenchMarker::output( const QString &message ) -{ - QTextStream out( stdout ); - out << message; -} - -void BenchMarker::testMaildir( QString dir ) -{ - currentInstance = createAgent( "akonadi_maildir_resource" ); - QTest::qWait( 1000 ); // HACK until resource startup races are fixed - - done = false; - qDebug() << " Configuring resource to use " << dir << "as source."; - QDBusInterface *configIface = new QDBusInterface( "org.freedesktop.Akonadi.Resource." + currentInstance.identifier(), - "/Settings", "org.kde.Akonadi.Maildir.Settings", QDBusConnection::sessionBus(), this ); - if ( configIface && configIface->isValid() ) { - configIface->call( "setPath", dir ); - configIface->call( "setReadOnly", true ); - } else { - qFatal( "Could not configure instance %s.", qPrintable( currentInstance.identifier() ) ); - } - - // import the complete email set - done = false; - timer.start(); - qDebug() << " Synchronising resource."; - currentInstance.synchronize(); - while(!done) - QTest::qWait( WAIT_TIME ); - outputStats( "import" ); - - // fetch all headers from each folder - timer.restart(); - qDebug() << " Listing all headers of every folder."; - CollectionFetchJob *clj = new CollectionFetchJob( Collection::root() , CollectionFetchJob::Recursive ); - clj->setResource( currentInstance.identifier() ); - clj->exec(); - Collection::List list = clj->collections(); - foreach ( const Collection &collection, list ) { - ItemFetchJob *ifj = new ItemFetchJob( collection, this ); - ifj->fetchScope().fetchPayloadPart( MessagePart::Envelope ); - ifj->exec(); - QString a; - foreach ( const Item &item, ifj->items() ) { - a = item.payload()->subject()->asUnicodeString(); - } - } - outputStats( "fullheaderlist" ); - - // mark 20% of messages as read - timer.restart(); - qDebug() << " Marking 20% of messages as read."; - CollectionFetchJob *clj2 = new CollectionFetchJob( Collection::root() , CollectionFetchJob::Recursive ); - clj2->setResource( currentInstance.identifier() ); - clj2->exec(); - Collection::List list2 = clj2->collections(); - foreach ( const Collection &collection, list2 ) { - ItemFetchJob *ifj = new ItemFetchJob( collection, this ); - ifj->exec(); - Item::List itemlist = ifj->items(); - for ( int i = ifj->items().count() - 1; i >= 0; i -= 5) { - Item item = itemlist[i]; - item.setFlag( "\\Seen" ); - ItemModifyJob *isj = new ItemModifyJob( item, this ); - isj->exec(); - } - } - outputStats( "mark20percentread" ); - - // fetch headers of unread messages from each folder - timer.restart(); - qDebug() << " Listing headers of unread messages of every folder."; - CollectionFetchJob *clj3 = new CollectionFetchJob( Collection::root() , CollectionFetchJob::Recursive ); - clj3->setResource( currentInstance.identifier() ); - clj3->exec(); - Collection::List list3 = clj3->collections(); - foreach ( const Collection &collection, list3 ) { - ItemFetchJob *ifj = new ItemFetchJob( collection, this ); - ifj->fetchScope().fetchPayloadPart( MessagePart::Envelope ); - ifj->exec(); - QString a; - foreach ( const Item &item, ifj->items() ) { - // filter read messages - if( !item.hasFlag( "\\Seen" ) ) { - a = item.payload()->subject()->asUnicodeString(); - } - } - } - outputStats( "unreadheaderlist" ); - - // remove all read messages from each folder - timer.restart(); - qDebug() << " Removing read messages from every folder."; - CollectionFetchJob *clj4 = new CollectionFetchJob( Collection::root() , CollectionFetchJob::Recursive ); - clj4->setResource( currentInstance.identifier() ); - clj4->exec(); - Collection::List list4 = clj4->collections(); - foreach ( const Collection &collection, list4 ) { - ItemFetchJob *ifj = new ItemFetchJob( collection, this ); - ifj->exec(); - foreach ( const Item &item, ifj->items() ) { - // delete read messages - if( item.hasFlag( "\\Seen" ) ) { - ItemDeleteJob *idj = new ItemDeleteJob( item, this); - idj->exec(); - } - } - } - outputStats( "removereaditems" ); - - // remove every folder sequentially - timer.restart(); - qDebug() << " Removing every folder sequentially."; - CollectionFetchJob *clj5 = new CollectionFetchJob( Collection::root() , CollectionFetchJob::Recursive ); - clj5->setResource( currentInstance.identifier() ); - clj5->exec(); - Collection::List list5 = clj5->collections(); - foreach ( const Collection &collection, list5 ) { - CollectionDeleteJob *cdj = new CollectionDeleteJob( collection, this ); - cdj->exec(); - } - outputStats( "removeallcollections" ); - - // remove resource - qDebug() << " Removing resource."; - AgentManager::self()->removeInstance( currentInstance ); -} - -int main( int argc, char* argv[] ) -{ - KCmdLineArgs::init( argc, argv, "benchmarker", 0, ki18n("Benchmarker") ,"1.0" ,ki18n("benchmark application") ); - - KCmdLineOptions options; - options.add("maildir ", ki18n("Path to maildir to be used as data source")); - KCmdLineArgs::addCmdLineOptions( options ); - KApplication app( false ); - KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); - QString maildir = args->getOption( "maildir" ); - - BenchMarker d( maildir ); - - return app.exec(); -} - -#include "benchmarker.moc" diff --git a/akonadi/tests/benchmarker.h b/akonadi/tests/benchmarker.h deleted file mode 100644 index 516b5c71b..000000000 --- a/akonadi/tests/benchmarker.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - Copyright (c) 2007 Robert Zwerus - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef BENCHMARKER_H -#define BENCHMARKER_H - -#include - -#include -#include - -using namespace Akonadi; - -class BenchMarker : public QObject -{ - Q_OBJECT - public: - BenchMarker( const QString &maildir ); - - private Q_SLOTS: - AgentInstance createAgent( const QString &name ); - void instanceRemoved( const Akonadi::AgentInstance &instance ); - void instanceStatusChanged( const Akonadi::AgentInstance &instance ); - void outputStats( const QString &description ); - void output( const QString &message ); - void stop(); - - private: - void testMaildir( QString dir ); - - AgentInstance currentInstance; - QString currentAccount; - QTime timer; - bool done; -}; - -#endif diff --git a/akonadi/tests/changerecordertest.cpp b/akonadi/tests/changerecordertest.cpp deleted file mode 100644 index e088c58ff..000000000 --- a/akonadi/tests/changerecordertest.cpp +++ /dev/null @@ -1,111 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include -#include -#include - -#include -#include - -#include - -using namespace Akonadi; - -Q_DECLARE_METATYPE(QSet) - -class ChangeRecorderTest : public QObject -{ - Q_OBJECT - private: - void triggerChange( int uid ) - { - Item item( uid ); - item.setFlag( "random_flag" ); - ItemModifyJob *job = new ItemModifyJob( item ); - job->disableRevisionCheck(); - QVERIFY( job->exec() ); - item.clearFlag( "random_flag" ); - job = new ItemModifyJob( item ); - job->disableRevisionCheck(); - QVERIFY( job->exec() ); - } - - private slots: - void initTestCase() - { - qRegisterMetaType(); - qRegisterMetaType >(); - } - - void testChangeRecorder() - { - QSettings *settings = new QSettings( "kde.org", "akonadi-changerecordertest", this ); - settings->clear(); - - ChangeRecorder *rec = new ChangeRecorder(); - rec->setConfig( settings ); - rec->setAllMonitored(); - - QSignalSpy spy( rec, SIGNAL(itemChanged(Akonadi::Item,QSet)) ); - QVERIFY( spy.isValid() ); - QSignalSpy cspy( rec, SIGNAL(changesAdded()) ); - QVERIFY( cspy.isValid() ); - - triggerChange( 1 ); - triggerChange( 1 ); - triggerChange( 3 ); - QTest::qWait( 1000 ); // enter event loop and wait for change notifications from the server - - QCOMPARE( spy.count(), 0 ); - QVERIFY( !cspy.isEmpty() ); - delete rec; - - rec = new ChangeRecorder(); - rec->setConfig( settings ); - rec->setAllMonitored(); - rec->itemFetchScope().fetchFullPayload(); - rec->itemFetchScope().fetchAllAttributes(); - QVERIFY( !rec->isEmpty() ); - - QSignalSpy spy2( rec, SIGNAL(itemChanged(Akonadi::Item,QSet)) ); - QVERIFY( spy2.isValid() ); - rec->replayNext(); - rec->changeProcessed(); - QVERIFY( !rec->isEmpty() ); - QTest::qWait( 1000 ); - QCOMPARE( spy2.count(), 1 ); - rec->replayNext(); - rec->changeProcessed(); - QVERIFY( rec->isEmpty() ); - QTest::qWait( 1000 ); - QCOMPARE( spy2.count(), 2 ); - - rec->replayNext(); - rec->changeProcessed(); - QVERIFY( rec->isEmpty() ); - QTest::qWait( 1000 ); - QCOMPARE( spy2.count(), 2 ); - delete rec; - } -}; - -QTEST_KDEMAIN( ChangeRecorderTest, NoGUI ) - -#include "changerecordertest.moc" diff --git a/akonadi/tests/collectionattributetest.cpp b/akonadi/tests/collectionattributetest.cpp deleted file mode 100644 index 08a80f844..000000000 --- a/akonadi/tests/collectionattributetest.cpp +++ /dev/null @@ -1,158 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "collectionattributetest.h" -#include "collectionattributetest.moc" -#include "collectionpathresolver_p.h" - -#include -#include -#include -#include -#include -#include -#include - -#include - -using namespace Akonadi; - -QTEST_KDEMAIN( CollectionAttributeTest, NoGUI ) - -class TestAttribute : public Attribute -{ - public: - TestAttribute() : Attribute() {} - TestAttribute( const QByteArray &data ) : mData( data ) {}; - TestAttribute* clone() const { return new TestAttribute( mData ); } - QByteArray type() const { return "TESTATTRIBUTE"; } - QByteArray serialized() const { return mData; } - void deserialize( const QByteArray &data ) { mData = data; } - private: - QByteArray mData; -}; - -static int parentColId = -1; - -void CollectionAttributeTest::initTestCase() -{ - Control::start(); - AttributeFactory::registerAttribute(); - - CollectionPathResolver *resolver = new CollectionPathResolver( "res3", this ); - QVERIFY( resolver->exec() ); - parentColId = resolver->collection(); - QVERIFY( parentColId > 0 ); -} - -void CollectionAttributeTest::testAttributes_data() -{ - QTest::addColumn("attr1"); - QTest::addColumn("attr2"); - - QTest::newRow("basic") << QByteArray("foo") << QByteArray("bar"); - QTest::newRow("emtpy1") << QByteArray("") << QByteArray("non-empty"); - QTest::newRow("empty2") << QByteArray("non-empty") << QByteArray(""); - QTest::newRow("space") << QByteArray("foo bar") << QByteArray("bar foo"); - QTest::newRow("quotes") << QByteArray("\"quoted \\ test\"") << QByteArray("single \" quote \\"); - QTest::newRow("parenthesis") << QByteArray(")") << QByteArray("("); - QTest::newRow("binary") << QByteArray("\000") << QByteArray("\001"); -} - -void CollectionAttributeTest::testAttributes() -{ - QFETCH( QByteArray, attr1 ); - QFETCH( QByteArray, attr2 ); - - // add a custom attribute - TestAttribute *attr = new TestAttribute(); - attr->deserialize( attr1 ); - Collection col; - col.setName( "attribute test" ); - col.setParent( parentColId ); - col.addAttribute( attr ); - CollectionCreateJob *create = new CollectionCreateJob( col, this ); - QVERIFY( create->exec() ); - col = create->collection(); - QVERIFY( col.isValid() ); - - attr = col.attribute(); - QVERIFY( attr != 0 ); - QCOMPARE( attr->serialized(), QByteArray( attr1 ) ); - - CollectionFetchJob *list = new CollectionFetchJob( col, CollectionFetchJob::Base, this ); - QVERIFY( list->exec() ); - QCOMPARE( list->collections().count(), 1 ); - col = list->collections().first(); - - QVERIFY( col.isValid() ); - attr = col.attribute(); - QVERIFY( attr != 0 ); - QCOMPARE( attr->serialized(), QByteArray( attr1 ) ); - - - // modify a custom attribute - col.attribute( Collection::AddIfMissing )->deserialize( attr2 ); - CollectionModifyJob *modify = new CollectionModifyJob( col, this ); - QVERIFY( modify->exec() ); - - list = new CollectionFetchJob( col, CollectionFetchJob::Base, this ); - QVERIFY( list->exec() ); - QCOMPARE( list->collections().count(), 1 ); - col = list->collections().first(); - - QVERIFY( col.isValid() ); - attr = col.attribute(); - QVERIFY( attr != 0 ); - QCOMPARE( attr->serialized(), QByteArray( attr2 ) ); - - - // delete a custom attribute - col.removeAttribute(); - modify = new CollectionModifyJob( col, this ); - QVERIFY( modify->exec() ); - - list = new CollectionFetchJob( col, CollectionFetchJob::Base, this ); - QVERIFY( list->exec() ); - QCOMPARE( list->collections().count(), 1 ); - col = list->collections().first(); - - QVERIFY( col.isValid() ); - attr = col.attribute(); - QVERIFY( attr == 0 ); - - - // cleanup - CollectionDeleteJob *del = new CollectionDeleteJob( col, this ); - QVERIFY( del->exec() ); - -} - -void CollectionAttributeTest::testDefaultAttributes() -{ - Collection col; - QCOMPARE( col.attributes().count(), 0 ); - Attribute* attr = AttributeFactory::createAttribute( "TYPE" ); - QVERIFY( attr ); - attr->deserialize( "VALUE" ); - col.addAttribute( attr ); - QCOMPARE( col.attributes().count(), 1 ); - QVERIFY( col.hasAttribute( "TYPE" ) ); - QCOMPARE( col.attribute( "TYPE" )->serialized(), QByteArray("VALUE") ); -} diff --git a/akonadi/tests/collectionattributetest.h b/akonadi/tests/collectionattributetest.h deleted file mode 100644 index aac80bc6b..000000000 --- a/akonadi/tests/collectionattributetest.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef COLLECTIONATTRIBUTETEST_H -#define COLLECTIONATTRIBUTETEST_H - -#include - -class CollectionAttributeTest : public QObject -{ - Q_OBJECT - private slots: - void initTestCase(); - void testAttributes_data(); - void testAttributes(); - void testDefaultAttributes(); -}; - - -#endif diff --git a/akonadi/tests/collectioncopytest.cpp b/akonadi/tests/collectioncopytest.cpp deleted file mode 100644 index 5d4a623fe..000000000 --- a/akonadi/tests/collectioncopytest.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include -#include -#include - -#include - -#include - -using namespace Akonadi; - -class CollectionCopyTest : public QObject -{ - Q_OBJECT - private slots: - void initTestCase() - { - Control::start(); - } - - void testCopy() - { - const Collection target( 8 ); - const Collection source( 10 ); - - CollectionCopyJob *copy = new CollectionCopyJob( source, target ); - QVERIFY( copy->exec() ); - - CollectionFetchJob *list = new CollectionFetchJob( target, CollectionFetchJob::Recursive ); - QVERIFY( list->exec() ); - QCOMPARE( list->collections().count(), 4 ); - - Collection copied = list->collections().first(); - QVERIFY( copied.remoteId().isEmpty() ); - QCOMPARE( copied.resource(), QString("akonadi_dummy_resource_3") ); - } - - void testIlleagalCopy() - { - // invalid source - CollectionCopyJob* copy = new CollectionCopyJob( Collection(), Collection( 1 ) ); - QVERIFY( !copy->exec() ); - - // non-existing source - copy = new CollectionCopyJob( Collection( INT_MAX ), Collection( 1 ) ); - QVERIFY( !copy->exec() ); - - // invalid target - copy = new CollectionCopyJob( Collection( 1 ), Collection() ); - QVERIFY( !copy->exec() ); - - // non-existing target - copy = new CollectionCopyJob( Collection( 1 ), Collection( INT_MAX ) ); - QVERIFY( !copy->exec() ); - } - -}; - -QTEST_KDEMAIN( CollectionCopyTest, NoGUI ) - -#include "collectioncopytest.moc" diff --git a/akonadi/tests/collectioncreator.cpp b/akonadi/tests/collectioncreator.cpp deleted file mode 100644 index e39298191..000000000 --- a/akonadi/tests/collectioncreator.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "collectioncreator.h" -#include "collectioncreatejob.h" -#include "collectionpathresolver_p.h" - -#include -#include - -#include -#include - -#define COLLECTION_COUNT 1000 - -using namespace Akonadi; - -CollectionCreator::CollectionCreator( ) -{ - jobCount = 0; - CollectionPathResolver *resolver = new CollectionPathResolver( "res3", this ); - if ( !resolver->exec() ) - qFatal( "Cannot resolve path." ); - int root = resolver->collection(); - startTime.start(); - for ( int i = 0; i < COLLECTION_COUNT; ++i ) { - Collection col; - col.setParent( root ); - col.setName( QLatin1String("col") + QString::number( i ) ); - CollectionCreateJob *job = new CollectionCreateJob( col, this ); - connect( job, SIGNAL(result(KJob*)), SLOT(done(KJob*)) ); - ++jobCount; - } -} - -void CollectionCreator::done( KJob * job ) -{ - if ( job->error() ) - qWarning() << "collection creation failed: " << job->errorString(); - --jobCount; - if ( jobCount <= 0 ) { - qDebug() << "creation took: " << startTime.elapsed() << "ms."; - qApp->quit(); - } -} - - -int main( int argc, char** argv ) -{ - KCmdLineArgs::init( argc, argv, "test", 0, ki18n("Test") ,"1.0" ,ki18n("test app") ); - KApplication app; - CollectionCreator *cc = new CollectionCreator(); - return app.exec(); - delete cc; -} - -#include "collectioncreator.moc" diff --git a/akonadi/tests/collectioncreator.h b/akonadi/tests/collectioncreator.h deleted file mode 100644 index 2f610dd48..000000000 --- a/akonadi/tests/collectioncreator.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef COLLECTIONCREATOR_H -#define COLLECTIONCREATOR_H - -#include -#include -#include - -class CollectionCreator : public QObject -{ - Q_OBJECT - public: - CollectionCreator(); - private Q_SLOTS: - void done(KJob *job); - private: - int jobCount; - QTime startTime; -}; - -#endif diff --git a/akonadi/tests/collectionjobtest.cpp b/akonadi/tests/collectionjobtest.cpp deleted file mode 100644 index 1b84a1eea..000000000 --- a/akonadi/tests/collectionjobtest.cpp +++ /dev/null @@ -1,546 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include - -#include "collectionjobtest.h" -#include - -#include "cachepolicy.h" -#include "collection.h" -#include "collectioncreatejob.h" -#include "collectiondeletejob.h" -#include "collectionfetchjob.h" -#include "collectionmodifyjob.h" -#include "collectionselectjob.h" -#include "collectionstatistics.h" -#include "collectionstatisticsjob.h" -#include "collectionpathresolver_p.h" -#include "collectionutils_p.h" -#include "control.h" -#include "item.h" -#include "kmime/messageparts.h" - -#include -#include - - - -using namespace Akonadi; - -QTEST_KDEMAIN( CollectionJobTest, NoGUI ) - -void CollectionJobTest::initTestCase() -{ - qRegisterMetaType(); - Control::start(); -} - -static Collection findCol( const Collection::List &list, const QString &name ) { - foreach ( const Collection &col, list ) - if ( col.name() == name ) - return col; - return Collection(); -} - -// list compare which ignores the order -template static void compareLists( const QList &l1, const QList &l2 ) -{ - QCOMPARE( l1.count(), l2.count() ); - foreach ( const T entry, l1 ) { - QVERIFY( l2.contains( entry ) ); - } -} - -template static T* extractAttribute( QList attrs ) -{ - T dummy; - foreach ( Attribute* attr, attrs ) { - if ( attr->type() == dummy.type() ) - return dynamic_cast( attr ); - } - return 0; -} - -static Collection::Id res1ColId = 6; // -1; -static Collection::Id res2ColId = 7; //-1; -static Collection::Id res3ColId = -1; -static Collection::Id searchColId = -1; - -void CollectionJobTest::testTopLevelList( ) -{ - // non-recursive top-level list - CollectionFetchJob *job = new CollectionFetchJob( Collection::root(), CollectionFetchJob::FirstLevel ); - QVERIFY( job->exec() ); - Collection::List list = job->collections(); - - // check if everything is there and has the correct types and attributes - QCOMPARE( list.count(), 4 ); - Collection col; - - col = findCol( list, "res1" ); - QVERIFY( col.isValid() ); - res1ColId = col.id(); // for the next test - QVERIFY( res1ColId > 0 ); - QVERIFY( CollectionUtils::isResource( col ) ); - QCOMPARE( col.parent(), Collection::root().id() ); - QCOMPARE( col.resource(), QLatin1String("akonadi_dummy_resource_1") ); - - QVERIFY( findCol( list, "res2" ).isValid() ); - res2ColId = findCol( list, "res2" ).id(); - QVERIFY( res2ColId > 0 ); - QVERIFY( findCol( list, "res3" ).isValid() ); - res3ColId = findCol( list, "res3" ).id(); - QVERIFY( res3ColId > 0 ); - - col = findCol( list, "Search" ); - searchColId = col.id(); - QVERIFY( col.isValid() ); - QVERIFY( CollectionUtils::isVirtualParent( col ) ); - QCOMPARE( col.resource(), QLatin1String("akonadi_search_resource") ); -} - -void CollectionJobTest::testFolderList( ) -{ - // recursive list of physical folders - CollectionFetchJob *job = new CollectionFetchJob( Collection( res1ColId ), CollectionFetchJob::Recursive ); - QSignalSpy spy( job, SIGNAL(collectionsReceived(Akonadi::Collection::List)) ); - QVERIFY( spy.isValid() ); - QVERIFY( job->exec() ); - Collection::List list = job->collections(); - - int count = 0; - for ( int i = 0; i < spy.count(); ++i ) { - Collection::List l = spy[i][0].value(); - for ( int j = 0; j < l.count(); ++j ) { - QVERIFY( list.count() > count + j ); - QCOMPARE( list[count + j].id(), l[j].id() ); - } - count += l.count(); - } - QCOMPARE( count, list.count() ); - - // check if everything is there - QCOMPARE( list.count(), 4 ); - Collection col; - QStringList contentTypes; - - col = findCol( list, "foo" ); - QVERIFY( col.isValid() ); - QCOMPARE( col.parent(), res1ColId ); - QVERIFY( CollectionUtils::isFolder( col ) ); - contentTypes << "message/rfc822" << "text/calendar" << "text/vcard" << "application/octet-stream"; - compareLists( col.contentMimeTypes(), contentTypes ); - - QVERIFY( findCol( list, "bar" ).isValid() ); - QCOMPARE( findCol( list, "bar" ).parent(), col.id() ); - QVERIFY( findCol( list, "bla" ).isValid() ); -} - -void CollectionJobTest::testNonRecursiveFolderList( ) -{ - CollectionFetchJob *job = new CollectionFetchJob( Collection( res1ColId ), CollectionFetchJob::Base ); - QVERIFY( job->exec() ); - Collection::List list = job->collections(); - - QCOMPARE( list.count(), 1 ); - QVERIFY( findCol( list, "res1" ).isValid() ); -} - -void CollectionJobTest::testEmptyFolderList( ) -{ - CollectionFetchJob *job = new CollectionFetchJob( Collection( res3ColId ), CollectionFetchJob::FirstLevel ); - QVERIFY( job->exec() ); - Collection::List list = job->collections(); - - QCOMPARE( list.count(), 0 ); -} - -void CollectionJobTest::testSearchFolderList( ) -{ - CollectionFetchJob *job = new CollectionFetchJob( Collection( searchColId ), CollectionFetchJob::FirstLevel ); - QVERIFY( job->exec() ); - Collection::List list = job->collections(); - - QCOMPARE( list.count(), 3 ); - Collection col = findCol( list, "Test ?er" ); - QVERIFY( col.isValid() ); - QVERIFY( CollectionUtils::isVirtual( col ) ); - QCOMPARE( col.resource(), QLatin1String("akonadi_search_resource" ) ); - QVERIFY( findCol( list, "all" ).isValid() ); - QVERIFY( findCol( list, "kde-core-devel" ).isValid() ); -} - -void CollectionJobTest::testResourceFolderList() -{ - // non-existing resource - CollectionFetchJob *job = new CollectionFetchJob( Collection::root(), CollectionFetchJob::FirstLevel ); - job->setResource( "i_dont_exist" ); - QVERIFY( !job->exec() ); - - // recursive listing of all collections of an existing resource - job = new CollectionFetchJob( Collection::root(), CollectionFetchJob::Recursive ); - job->setResource( "akonadi_dummy_resource_1" ); - QVERIFY( job->exec() ); - - Collection::List list = job->collections(); - QCOMPARE( list.count(), 5 ); - QVERIFY( findCol( list, "res1" ).isValid() ); - QVERIFY( findCol( list, "foo" ).isValid() ); - QVERIFY( findCol( list, "bar" ).isValid() ); - QVERIFY( findCol( list, "bla" ).isValid() ); - int fooId = findCol( list, "foo" ).id(); - - // limited listing of a resource - job = new CollectionFetchJob( Collection( fooId ), CollectionFetchJob::Recursive ); - job->setResource( "akonadi_dummy_resource_1" ); - QVERIFY( job->exec() ); - - list = job->collections(); - QCOMPARE( list.count(), 3 ); - QVERIFY( findCol( list, "bar" ).isValid() ); - QVERIFY( findCol( list, "bla" ).isValid() ); -} - -void CollectionJobTest::testCreateDeleteFolder_data() -{ - QTest::addColumn("collection"); - QTest::addColumn("creatable"); - - Collection col; - QTest::newRow("empty") << col << false; - col.setName( "new folder" ); - col.setParent( res3ColId ); - QTest::newRow("simple") << col << true; - - col.setParent( res3ColId ); - col.setName( "foo" ); - QTest::newRow( "existing in different resource" ) << col << true; - - col.setName( "mail folder" ); - QStringList mimeTypes; - mimeTypes << "inode/directory" << "message/rfc822"; - col.setContentMimeTypes( mimeTypes ); - col.setRemoteId( "remote id" ); - CachePolicy policy; - policy.setInheritFromParent( false ); - policy.setIntervalCheckTime( 60 ); - policy.setLocalParts( QStringList( MessagePart::Envelope ) ); - policy.setSyncOnDemand( true ); - policy.setCacheTimeout( 120 ); - col.setCachePolicy( policy ); - QTest::newRow( "complex" ) << col << true; - - col = Collection(); - col.setName( "New Folder" ); - col.setParent( searchColId ); - QTest::newRow( "search folder" ) << col << false; - - col.setParent( res2ColId ); - col.setName( "foo2" ); - QTest::newRow( "already existing" ) << col << false; - - col.setName( "Bla" ); - col.setParent( 2 ); - QTest::newRow( "already existing with different case" ) << col << true; - - CollectionPathResolver *resolver = new CollectionPathResolver( "res2/foo2", this ); - QVERIFY( resolver->exec() ); - col.setParent( resolver->collection() ); - col.setName( "new folder" ); - QTest::newRow( "parent noinferior" ) << col << false; - - col.setParent( INT_MAX ); - QTest::newRow( "missing parent" ) << col << false; -} - -void CollectionJobTest::testCreateDeleteFolder() -{ - QFETCH( Collection, collection ); - QFETCH( bool, creatable ); - - CollectionCreateJob *createJob = new CollectionCreateJob( collection, this ); - QCOMPARE( createJob->exec(), creatable ); - if ( !creatable ) - return; - - Collection createdCol = createJob->collection(); - QVERIFY( createdCol.isValid() ); - QCOMPARE( createdCol.name(), collection.name() ); - QCOMPARE( createdCol.parent(), collection.parent() ); - QCOMPARE( createdCol.remoteId(), collection.remoteId() ); - QCOMPARE( createdCol.cachePolicy(), collection.cachePolicy() ); - - CollectionFetchJob *listJob = new CollectionFetchJob( Collection( collection.parent() ), CollectionFetchJob::FirstLevel, this ); - QVERIFY( listJob->exec() ); - Collection listedCol = findCol( listJob->collections(), collection.name() ); - QCOMPARE( listedCol, createdCol ); - QCOMPARE( listedCol.remoteId(), collection.remoteId() ); - QCOMPARE( listedCol.cachePolicy(), collection.cachePolicy() ); - - // fetch parent to compare inherited collection properties - Collection parentCol = Collection::root(); - if ( collection.parent() > 0 ) { - CollectionFetchJob *listJob = new CollectionFetchJob( Collection( collection.parent() ), CollectionFetchJob::Base, this ); - QVERIFY( listJob->exec() ); - QCOMPARE( listJob->collections().count(), 1 ); - parentCol = listJob->collections().first(); - } - - if ( collection.contentMimeTypes().isEmpty() ) - compareLists( listedCol.contentMimeTypes(), parentCol.contentMimeTypes() ); - else - compareLists( listedCol.contentMimeTypes(), collection.contentMimeTypes() ); - - if ( collection.resource().isEmpty() ) - QCOMPARE( listedCol.resource(), parentCol.resource() ); - else - QCOMPARE( listedCol.resource(), collection.resource() ); - - CollectionDeleteJob *delJob = new CollectionDeleteJob( createdCol, this ); - QVERIFY( delJob->exec() ); - - listJob = new CollectionFetchJob( Collection( collection.parent() ), CollectionFetchJob::FirstLevel, this ); - QVERIFY( listJob->exec() ); - QVERIFY( !findCol( listJob->collections(), collection.name() ).isValid() ); -} - -void CollectionJobTest::testIllegalDeleteFolder() -{ - // non-existing folder - CollectionDeleteJob *del = new CollectionDeleteJob( Collection( INT_MAX ), this ); - QVERIFY( !del->exec() ); - - // root - del = new CollectionDeleteJob( Collection::root(), this ); - QVERIFY( !del->exec() ); -} - -void CollectionJobTest::testStatistics() -{ - // empty folder - CollectionStatisticsJob *statistics = - new CollectionStatisticsJob( Collection( res1ColId ), this ); - QVERIFY( statistics->exec() ); - - CollectionStatistics s = statistics->statistics(); - QCOMPARE( s.count(), 0ll ); - QCOMPARE( s.unreadCount(), 0ll ); - - // folder with attributes and content - CollectionPathResolver *resolver = new CollectionPathResolver( "res1/foo", this );; - QVERIFY( resolver->exec() ); - statistics = new CollectionStatisticsJob( Collection( resolver->collection() ), this ); - QVERIFY( statistics->exec() ); - - s = statistics->statistics(); - QCOMPARE( s.count(), 15ll ); - QCOMPARE( s.unreadCount(), 14ll ); -} - -void CollectionJobTest::testModify() -{ - QStringList reference; - reference << "text/calendar" << "text/vcard" << "message/rfc822" << "application/octet-stream"; - - Collection col; - CollectionFetchJob *ljob = new CollectionFetchJob( Collection( res1ColId ), CollectionFetchJob::FirstLevel ); - QVERIFY( ljob->exec() ); - col = findCol( ljob->collections(), "foo" ); - QVERIFY( col.isValid() ); - - // test noop modify - CollectionModifyJob *mod = new CollectionModifyJob( col, this ); - QVERIFY( mod->exec() ); - - ljob = new CollectionFetchJob( col, CollectionFetchJob::Base, this ); - QVERIFY( ljob->exec() ); - QCOMPARE( ljob->collections().count(), 1 ); - col = ljob->collections().first(); - compareLists( col.contentMimeTypes(), reference ); - - // test clearing content types - col.setContentMimeTypes( QStringList() ); - mod = new CollectionModifyJob( col, this ); - QVERIFY( mod->exec() ); - - ljob = new CollectionFetchJob( col, CollectionFetchJob::Base, this ); - QVERIFY( ljob->exec() ); - QCOMPARE( ljob->collections().count(), 1 ); - col = ljob->collections().first(); - QVERIFY( col.contentMimeTypes().isEmpty() ); - - // test setting contnet types - col.setContentMimeTypes( reference ); - mod = new CollectionModifyJob( col, this ); - QVERIFY( mod->exec() ); - - ljob = new CollectionFetchJob( col, CollectionFetchJob::Base, this ); - QVERIFY( ljob->exec() ); - QCOMPARE( ljob->collections().count(), 1 ); - col = ljob->collections().first(); - compareLists( col.contentMimeTypes(), reference ); - - // renaming - col.setName( "foo (renamed)" ); - mod = new CollectionModifyJob( col, this ); - QVERIFY( mod->exec() ); - - ljob = new CollectionFetchJob( col, CollectionFetchJob::Base, this ); - QVERIFY( ljob->exec() ); - QCOMPARE( ljob->collections().count(), 1 ); - col = ljob->collections().first(); - QCOMPARE( col.name(), QString( "foo (renamed)" ) ); - - col.setName( "foo" ); - mod = new CollectionModifyJob( col, this ); - QVERIFY( mod->exec() ); -} - -void CollectionJobTest::testMove() -{ - Collection col( res1ColId ); - col.setParent( res2ColId ); - CollectionModifyJob *mod = new CollectionModifyJob( col, this ); - QVERIFY( mod->exec() ); - - CollectionFetchJob *ljob = new CollectionFetchJob( Collection( res2ColId ), CollectionFetchJob::Recursive ); - QVERIFY( ljob->exec() ); - Collection::List list = ljob->collections(); - - QCOMPARE( list.count(), 7 ); - QVERIFY( findCol( list, "res1" ).isValid() ); - QVERIFY( findCol( list, "foo" ).isValid() ); - QVERIFY( findCol( list, "bar" ).isValid() ); - QVERIFY( findCol( list, "bla" ).isValid() ); - - ljob = new CollectionFetchJob( Collection( res1ColId ), CollectionFetchJob::Base ); - QVERIFY( ljob->exec() ); - list = ljob->collections(); - - QCOMPARE( list.count(), 1 ); - col = list.first(); - QCOMPARE( col.name(), QLatin1String("res1") ); - QCOMPARE( col.parent(), res2ColId ); - - // cleanup - col.setParent( Collection::root() ); - mod = new CollectionModifyJob( col, this ); - QVERIFY( mod->exec() ); -} - -void CollectionJobTest::testIllegalModify() -{ - // non-existing collection - Collection col( INT_MAX ); - col.setParent( res1ColId ); - CollectionModifyJob *mod = new CollectionModifyJob( col, this ); - QVERIFY( !mod->exec() ); - - // rename to already existing name - col = Collection( res1ColId ); - col.setName( "res2" ); - mod = new CollectionModifyJob( col, this ); - QVERIFY( !mod->exec() ); - - // move to non-existing target - col = Collection( res1ColId ); - col.setParent( INT_MAX ); - mod = new CollectionModifyJob( col, this ); - QVERIFY( !mod->exec() ); - - // moving root - col = Collection::root(); - col.setParent( res1ColId ); - mod = new CollectionModifyJob( col, this ); - QVERIFY( !mod->exec() ); -} - -void CollectionJobTest::testUtf8CollectionName() -{ - QString folderName = QString::fromUtf8( "ä" ); - - // create collection - Collection col; - col.setParent( res3ColId ); - col.setName( folderName ); - CollectionCreateJob *create = new CollectionCreateJob( col, this ); - QVERIFY( create->exec() ); - col = create->collection(); - QVERIFY( col.isValid() ); - - // list parent - CollectionFetchJob *list = new CollectionFetchJob( Collection( res3ColId ), CollectionFetchJob::Recursive, this ); - QVERIFY( list->exec() ); - QCOMPARE( list->collections().count(), 1 ); - QCOMPARE( col, list->collections().first() ); - QCOMPARE( col.name(), folderName ); - - // modify collection - col.setContentMimeTypes( QStringList( "message/rfc822'" ) ); - CollectionModifyJob *modify = new CollectionModifyJob( col, this ); - QVERIFY( modify->exec() ); - - // collection statistics - CollectionStatisticsJob *statistics = new CollectionStatisticsJob( col, this ); - QVERIFY( statistics->exec() ); - CollectionStatistics s = statistics->statistics(); - QCOMPARE( s.count(), 0ll ); - QCOMPARE( s.unreadCount(), 0ll ); - - // delete collection - CollectionDeleteJob *del = new CollectionDeleteJob( col, this ); - QVERIFY( del->exec() ); -} - -void CollectionJobTest::testMultiList() -{ - Collection::List req; - req << Collection( res1ColId ) << Collection( res2ColId ); - CollectionFetchJob* job = new CollectionFetchJob( req, this ); - QVERIFY( job->exec() ); - - Collection::List res; - res = job->collections(); - compareLists( res, req ); -} - -void CollectionJobTest::testSelect() -{ - CollectionPathResolver *resolver = new CollectionPathResolver( "res1/foo", this );; - QVERIFY( resolver->exec() ); - Collection col( resolver->collection() ); - - CollectionSelectJob *job = new CollectionSelectJob( col, this ); - QVERIFY( job->exec() ); - QCOMPARE( job->unseen(), -1 ); - - job = new CollectionSelectJob( col, this ); - job->setRetrieveStatus( true ); - QVERIFY( job->exec() ); - QVERIFY( job->unseen() > -1 ); - - job = new CollectionSelectJob( Collection::root(), this ); - QVERIFY( job->exec() ); - - job = new CollectionSelectJob( Collection( INT_MAX ), this ); - QVERIFY( !job->exec() ); -} - -#include "collectionjobtest.moc" diff --git a/akonadi/tests/collectionjobtest.h b/akonadi/tests/collectionjobtest.h deleted file mode 100644 index 92ae18bdb..000000000 --- a/akonadi/tests/collectionjobtest.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef COLLECTIONJOBTEST_H -#define COLLECTIONJOBTEST_H - -#include - -class CollectionJobTest : public QObject -{ - Q_OBJECT - private Q_SLOTS: - void initTestCase(); - void testTopLevelList(); - void testFolderList(); - void testNonRecursiveFolderList(); - void testEmptyFolderList(); - void testSearchFolderList(); - void testResourceFolderList(); - void testCreateDeleteFolder_data(); - void testCreateDeleteFolder(); - void testIllegalDeleteFolder(); - void testStatistics(); - void testModify(); - void testMove(); - void testIllegalModify(); - void testUtf8CollectionName(); - void testMultiList(); - void testSelect(); -}; - - -#endif diff --git a/akonadi/tests/collectionpathresolvertest.cpp b/akonadi/tests/collectionpathresolvertest.cpp deleted file mode 100644 index 9c268890f..000000000 --- a/akonadi/tests/collectionpathresolvertest.cpp +++ /dev/null @@ -1,67 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "collectionpathresolvertest.h" -#include "collectionpathresolvertest.moc" -#include "collectionpathresolver_p.h" - -#include - -#include - -using namespace Akonadi; - -QTEST_KDEMAIN( CollectionPathResolverTest, NoGUI ) - -void CollectionPathResolverTest::initTestCase() -{ - Control::start(); -} - -void CollectionPathResolverTest::testPathResolver() -{ - CollectionPathResolver *resolver = new CollectionPathResolver( "/res1/foo/bar/bla", this ); - QVERIFY( resolver->exec() ); - int col = resolver->collection(); - QVERIFY( col > 0 ); - - resolver = new CollectionPathResolver( Collection( col ), this ); - QVERIFY( resolver->exec() ); - QCOMPARE( resolver->path(), QString( "res1/foo/bar/bla" ) ); -} - -void CollectionPathResolverTest::testRoot() -{ - CollectionPathResolver *resolver = new CollectionPathResolver( CollectionPathResolver::pathDelimiter(), this ); - QVERIFY( resolver->exec() ); - QCOMPARE( resolver->collection(), Collection::root().id() ); - - resolver = new CollectionPathResolver( Collection::root(), this ); - QVERIFY( resolver->exec() ); - QVERIFY( resolver->path().isEmpty() ); -} - -void CollectionPathResolverTest::testFailure() -{ - CollectionPathResolver *resolver = new CollectionPathResolver( "/I/do not/exist", this ); - QVERIFY( !resolver->exec() ); - - resolver = new CollectionPathResolver( Collection( INT_MAX ), this ); - QVERIFY( !resolver->exec() ); -} diff --git a/akonadi/tests/collectionpathresolvertest.h b/akonadi/tests/collectionpathresolvertest.h deleted file mode 100644 index 11a1a40c4..000000000 --- a/akonadi/tests/collectionpathresolvertest.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef COLLECTIONPATHRESOLVER_TEST_H -#define COLLECTIONPATHRESOLVER_TEST_H - -#include - -class CollectionPathResolverTest : public QObject -{ - Q_OBJECT - private slots: - void initTestCase(); - void testPathResolver(); - void testRoot(); - void testFailure(); -}; - - -#endif diff --git a/akonadi/tests/headfetcher.cpp b/akonadi/tests/headfetcher.cpp deleted file mode 100644 index e20d1a898..000000000 --- a/akonadi/tests/headfetcher.cpp +++ /dev/null @@ -1,90 +0,0 @@ -/* - Copyright (c) 2007 Robert Zwerus - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "headfetcher.h" - -#include -#include -#include -#include "kmime/messageparts.h" - -#include -#include -#include -#include - -#include - -#include -#include -#include - -#include - -using namespace Akonadi; - -HeadFetcher::HeadFetcher( bool multipart ) -{ - // fetch all headers from each folder - timer.start(); - qDebug() << "Listing all headers of every folder, using" << (multipart ? "multi" : "single") << "part."; - CollectionFetchJob *clj = new CollectionFetchJob( Collection::root() , CollectionFetchJob::Recursive ); - clj->exec(); - Collection::List list = clj->collections(); - foreach ( const Collection &collection, list ) { - ItemFetchJob *ifj = new ItemFetchJob( collection, this ); - if ( multipart ) { - ifj->fetchScope().fetchPayloadPart( MessagePart::Envelope ); - } else { - ifj->fetchScope().fetchFullPayload(); - } - ifj->exec(); - qDebug() << " Listing" << ifj->items().count() << "item headers."; - foreach ( const Item &item, ifj->items() ) { - qDebug() << item.payload< boost::shared_ptr >()->subject()->asUnicodeString(); - } - } - - qDebug() << "Took:" << timer.elapsed() << "ms."; - QTimer::singleShot( 1000, this, SLOT( stop() ) ); -} - -void HeadFetcher::stop() -{ - qApp->quit(); -} - -int main( int argc, char* argv[] ) -{ - KCmdLineArgs::init( argc, argv, "headfetcher", 0, ki18n("Headfetcher") ,"1.0" ,ki18n("header fetching application") ); - - KCmdLineOptions options; - options.add("multipart", ki18n("Run test on multipart data (default is singlepart).")); - KCmdLineArgs::addCmdLineOptions( options ); - KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); - bool multipart = args->isSet( "multipart" ); - - KApplication app( false ); - - HeadFetcher d( multipart ); - - return app.exec(); -} - -#include "headfetcher.moc" diff --git a/akonadi/tests/headfetcher.h b/akonadi/tests/headfetcher.h deleted file mode 100644 index 17ce75fa7..000000000 --- a/akonadi/tests/headfetcher.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - Copyright (c) 2007 Robert Zwerus - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef HEADFETCHER_H -#define HEADFETCHER_H - -#include -#include - -class HeadFetcher : public QObject -{ - Q_OBJECT - public: - HeadFetcher( bool multipart ); - private Q_SLOTS: - void stop(); - private: - QTime timer; -}; - -#endif diff --git a/akonadi/tests/imapparsertest.cpp b/akonadi/tests/imapparsertest.cpp deleted file mode 100644 index 93d0c5517..000000000 --- a/akonadi/tests/imapparsertest.cpp +++ /dev/null @@ -1,525 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "imapparsertest.h" -#include -#include - -#include -#include - -Q_DECLARE_METATYPE( QList ) -Q_DECLARE_METATYPE( QList ) - -using namespace Akonadi; - -QTEST_KDEMAIN( ImapParserTest, NoGUI ) - -void ImapParserTest::testStripLeadingSpaces( ) -{ - QByteArray input = " a "; - int result; - - // simple leading spaces at the beginning - result = ImapParser::stripLeadingSpaces( input, 0 ); - QCOMPARE( result, 2 ); - - // simple leading spaces in the middle - result = ImapParser::stripLeadingSpaces( input, 1 ); - QCOMPARE( result, 2 ); - - // no leading spaces - result = ImapParser::stripLeadingSpaces( input, 2 ); - QCOMPARE( result, 2 ); - - // trailing spaces - result = ImapParser::stripLeadingSpaces( input, 3 ); - QCOMPARE( result, 5 ); - - // out of bounds access - result = ImapParser::stripLeadingSpaces( input, input.length() ); - QCOMPARE( result, input.length() ); -} - -void ImapParserTest::testParseQuotedString( ) -{ - QByteArray input = "\"quoted \\\"NIL\\\" string inside\""; - QByteArray result; - int consumed; - - // the whole thing - consumed = ImapParser::parseQuotedString( input, result, 0 ); - QCOMPARE( result, QByteArray( "quoted \"NIL\" string inside" ) ); - QCOMPARE( consumed, 32 ); - - // unqoted string - consumed = ImapParser::parseQuotedString( input, result, 1 ); - QCOMPARE( result, QByteArray( "quoted" ) ); - QCOMPARE( consumed, 7 ); - - // whitespaces in qouted string - consumed = ImapParser::parseQuotedString( input, result, 14 ); - QCOMPARE( result, QByteArray( " string inside" ) ); - QCOMPARE( consumed, 32 ); - - // whitespaces before unquoted string - consumed = ImapParser::parseQuotedString( input, result, 15 ); - QCOMPARE( result, QByteArray( "string" ) ); - QCOMPARE( consumed, 24 ); - - - // NIL and emptyness tests - input = "NIL \"NIL\" \"\""; - - // unqoted NIL - consumed = ImapParser::parseQuotedString( input, result, 0 ); - QVERIFY( result.isNull() ); - QCOMPARE( consumed, 3 ); - - // quoted NIL - consumed = ImapParser::parseQuotedString( input, result, 3 ); - QCOMPARE( result, QByteArray( "NIL" ) ); - QCOMPARE( consumed, 9 ); - - // quoted empty string - consumed = ImapParser::parseQuotedString( input, result, 9 ); - QCOMPARE( result, QByteArray( "" ) ); - QCOMPARE( consumed, 12 ); - - // unquoted string at input end - input = "some string"; - consumed = ImapParser::parseQuotedString( input, result, 4 ); - QCOMPARE( result, QByteArray( "string" ) ); - QCOMPARE( consumed, 11 ); - - // out of bounds access - consumed = ImapParser::parseQuotedString( input, result, input.length() ); - QVERIFY( result.isEmpty() ); - QCOMPARE( consumed, input.length() ); - - // de-quoting - input = "\"\\\"some \\\\ quoted stuff\\\"\""; - consumed = ImapParser::parseQuotedString( input, result, 0 ); - QCOMPARE( result, QByteArray( "\"some \\ quoted stuff\"" ) ); - QCOMPARE( consumed, input.length() ); - - // linebreak as separator - input = "LOGOUT\nFOO"; - consumed = ImapParser::parseQuotedString( input, result, 0 ); - QCOMPARE( result, QByteArray("LOGOUT") ); - QCOMPARE( consumed, 6 ); -} - -void ImapParserTest::testParseString( ) -{ - QByteArray input = "\"quoted\" unquoted {7}\nliteral {0}\n empty literal"; - QByteArray result; - int consumed; - - // quoted strings - consumed = ImapParser::parseString( input, result, 0 ); - QCOMPARE( result, QByteArray( "quoted" ) ); - QCOMPARE( consumed, 8 ); - - // unquoted string - consumed = ImapParser::parseString( input, result, 8 ); - QCOMPARE( result, QByteArray( "unquoted" ) ); - QCOMPARE( consumed, 17 ); - - // literal string - consumed = ImapParser::parseString( input, result, 17 ); - QCOMPARE( result, QByteArray( "literal" ) ); - QCOMPARE( consumed, 29 ); - - // empty literal string - consumed = ImapParser::parseString( input, result, 29 ); - QCOMPARE( result, QByteArray( "" ) ); - QCOMPARE( consumed, 34 ); - - // out of bounds access - consumed = ImapParser::parseString( input, result, input.length() ); - QCOMPARE( result, QByteArray() ); - QCOMPARE( consumed, input.length() ); -} - -void ImapParserTest::testParseParenthesizedList( ) -{ - QByteArray input; - QList result; - int consumed; - - // empty lists - input = "() ( )"; - consumed = ImapParser::parseParenthesizedList( input, result, 0 ); - QVERIFY( result.isEmpty() ); - QCOMPARE( consumed, 2 ); - - consumed = ImapParser::parseParenthesizedList( input, result, 2 ); - QVERIFY( result.isEmpty() ); - QCOMPARE( consumed, 6 ); - - // complex list with all kind of entries - input = "(entry1 \"entry2()\" (sub list) \")))\" {6}\nentry3) end"; - consumed = ImapParser::parseParenthesizedList( input, result, 0 ); - QList reference; - reference << "entry1"; - reference << "entry2()"; - reference << "(sub list)"; - reference << ")))"; - reference << "entry3"; - QCOMPARE( result, reference ); - QCOMPARE( consumed, 47 ); - - // no list at all - input = "some list-less text"; - consumed = ImapParser::parseParenthesizedList( input, result, 0 ); - QVERIFY( result.isEmpty() ); - QCOMPARE( consumed, 0 ); - - // out of bounds access - consumed = ImapParser::parseParenthesizedList( input, result, input.length() ); - QVERIFY( result.isEmpty() ); - QCOMPARE( consumed, input.length() ); - - // newline literal (based on itemappendtest bug) - input = "(foo {6}\n\n\nbar\n bla)"; - consumed = ImapParser::parseParenthesizedList( input, result ); - reference.clear(); - reference << "foo"; - reference << "\n\nbar\n"; - reference << "bla"; - QCOMPARE( result, reference ); - QCOMPARE( consumed, input.length() ); -} - -void ImapParserTest::testParseNumber() -{ - QByteArray input = " 1a23.4"; - qint64 result; - int pos; - bool ok; - - // empty string - pos = ImapParser::parseNumber( QByteArray(), result, &ok ); - QCOMPARE( ok, false ); - QCOMPARE( pos, 0 ); - - // leading spaces at the beginning - pos = ImapParser::parseNumber( input, result, &ok, 0 ); - QCOMPARE( ok, true ); - QCOMPARE( pos, 2 ); - QCOMPARE( result, 1ll ); - - // multiple digits - pos = ImapParser::parseNumber( input, result, &ok, 3 ); - QCOMPARE( ok, true ); - QCOMPARE( pos, 5 ); - QCOMPARE( result, 23ll ); - - // number at input end - pos = ImapParser::parseNumber( input, result, &ok, 6 ); - QCOMPARE( ok, true ); - QCOMPARE( pos, 7 ); - QCOMPARE( result, 4ll ); - - // out of bounds access - pos = ImapParser::parseNumber( input, result, &ok, input.length() ); - QCOMPARE( ok, false ); - QCOMPARE( pos, input.length() ); -} - -void ImapParserTest::testQuote_data() -{ - QTest::addColumn( "unquoted" ); - QTest::addColumn( "quoted" ); - - QTest::newRow( "empty" ) << QByteArray("") << QByteArray("\"\""); - QTest::newRow( "simple" ) << QByteArray("bla") << QByteArray("\"bla\""); - QTest::newRow( "double-quotes" ) << QByteArray("\"test\"test\"") << QByteArray("\"\\\"test\\\"test\\\"\""); - QTest::newRow( "backslash" ) << QByteArray("\\") << QByteArray("\"\\\\\""); - QByteArray binaryNonEncoded; - binaryNonEncoded += '\000'; - QByteArray binaryEncoded("\"" ); - binaryEncoded += '\000'; - binaryEncoded += '"'; - QTest::newRow( "binary" ) << binaryNonEncoded << binaryEncoded; -} - -void ImapParserTest::testQuote() -{ - QFETCH( QByteArray, unquoted ); - QFETCH( QByteArray, quoted ); - QCOMPARE( ImapParser::quote( unquoted ), quoted ); -} - -void ImapParserTest::testMessageParser_data() -{ - QTest::addColumn >( "input" ); - QTest::addColumn( "tag" ); - QTest::addColumn( "data" ); - QTest::addColumn( "complete" ); - QTest::addColumn >( "continuations" ); - - QList input; - QList continuations; - QTest::newRow( "empty" ) << input << QByteArray() << QByteArray() << false << continuations; - - input << "*"; - QTest::newRow( "tag-only" ) << input << QByteArray("*") << QByteArray() << true << continuations; - - input.clear(); - input << "20 UID FETCH (foo)"; - QTest::newRow( "simple" ) << input << QByteArray("20") - << QByteArray( "UID FETCH (foo)" ) << true << continuations; - - input.clear(); - input << "1 (bla (" << ") blub)"; - QTest::newRow( "parenthesis" ) << input << QByteArray("1") - << QByteArray( "(bla () blub)" ) << true << continuations; - - input.clear(); - input << "1 {3}" << "bla"; - continuations << 0; - QTest::newRow( "literal" ) << input << QByteArray("1") << QByteArray("{3}bla") - << true << continuations; - - input.clear(); - input << "1 FETCH (UID 5 DATA {3}" - << "bla" - << " RID 5)"; - QTest::newRow( "parenthesisEnclosedLiteral" ) << input << QByteArray("1") - << QByteArray( "FETCH (UID 5 DATA {3}bla RID 5)" ) << true << continuations; - - input.clear(); - input << "1 {3}" << "bla {4}" << "blub"; - continuations.clear(); - continuations << 0 << 1; - QTest::newRow( "2literal" ) << input << QByteArray("1") - << QByteArray("{3}bla {4}blub") << true << continuations; - - input.clear(); - input << "1 {4}" << "A{9}"; - continuations.clear(); - continuations << 0; - QTest::newRow( "literal in literal" ) << input << QByteArray("1") - << QByteArray("{4}A{9}") << true << continuations; - - input.clear(); - input << "* FETCH (UID 1 DATA {3}" << "bla" << " ENVELOPE {4}" << "blub" << " RID 5)"; - continuations.clear(); - continuations << 0 << 2; - QTest::newRow( "enclosed2literal" ) << input << QByteArray("*") - << QByteArray( "FETCH (UID 1 DATA {3}bla ENVELOPE {4}blub RID 5)" ) - << true << continuations; - - input.clear(); - input << "1 DATA {0}"; - continuations.clear(); - QTest::newRow( "empty literal" ) << input << QByteArray( "1" ) - << QByteArray( "DATA {0}" ) << true << continuations; -} - -void ImapParserTest::testMessageParser() -{ - QFETCH( QList, input ); - QFETCH( QByteArray, tag ); - QFETCH( QByteArray, data ); - QFETCH( bool, complete ); - QFETCH( QList, continuations ); - QList cont = continuations; - - ImapParser *parser = new ImapParser(); - QVERIFY( parser->tag().isEmpty() ); - QVERIFY( parser->data().isEmpty() ); - - for ( int i = 0; i < input.count(); ++i ) { - bool res = parser->parseNextLine( input.at( i ) ); - if ( i != input.count() - 1 ) - QVERIFY( !res ); - else - QCOMPARE( res, complete ); - if ( parser->continuationStarted() ) { - QVERIFY( cont.contains( i ) ); - cont.removeAll( i ); - } - } - - QCOMPARE( parser->tag(), tag ); - QCOMPARE( parser->data(), data ); - QVERIFY( cont.isEmpty() ); - - // try again, this time with a not fresh parser - parser->reset(); - QVERIFY( parser->tag().isEmpty() ); - QVERIFY( parser->data().isEmpty() ); - cont = continuations; - - for ( int i = 0; i < input.count(); ++i ) { - bool res = parser->parseNextLine( input.at( i ) ); - if ( i != input.count() - 1 ) - QVERIFY( !res ); - else - QCOMPARE( res, complete ); - if ( parser->continuationStarted() ) { - QVERIFY( cont.contains( i ) ); - cont.removeAll( i ); - } - } - - QCOMPARE( parser->tag(), tag ); - QCOMPARE( parser->data(), data ); - QVERIFY( cont.isEmpty() ); - - delete parser; -} - -void ImapParserTest::testParseSequenceSet_data() -{ - QTest::addColumn( "data" ); - QTest::addColumn( "begin" ); - QTest::addColumn( "result" ); - QTest::addColumn( "end" ); - - QByteArray data( " 1 0:* 3:4,8:* *:5,1" ); - - QTest::newRow( "empty" ) << QByteArray() << 0 << ImapInterval::List() << 0; - QTest::newRow( "input end" ) << data << 20 << ImapInterval::List() << 20; - - ImapInterval::List result; - result << ImapInterval( 1, 1 ); - QTest::newRow( "single value 1" ) << data << 0 << result << 2; - QTest::newRow( "single value 2" ) << data << 1 << result << 2; - QTest::newRow( "single value 3" ) << data << 19 << result << 20; - - result.clear(); - result << ImapInterval(); - QTest::newRow( "full interval" ) << data << 2 << result << 6; - - result.clear(); - result << ImapInterval( 3, 4 ) << ImapInterval( 8 ); - QTest::newRow( "complex 1" ) << data << 7 << result << 14; - - result.clear(); - result << ImapInterval( 0, 5 ) << ImapInterval( 1, 1 ); - QTest::newRow( "complex 2" ) << data << 14 << result << 20; -} - -void ImapParserTest::testParseSequenceSet() -{ - QFETCH( QByteArray, data ); - QFETCH( int, begin ); - QFETCH( ImapInterval::List, result ); - QFETCH( int, end ); - - ImapSet res; - int pos = ImapParser::parseSequenceSet( data, res, begin ); - QCOMPARE( res.intervals(), result ); - QCOMPARE( pos, end ); -} - -void ImapParserTest::testParseDateTime_data() -{ - QTest::addColumn( "data" ); - QTest::addColumn( "begin" ); - QTest::addColumn( "result" ); - QTest::addColumn( "end" ); - - QTest::newRow( "emtpy" ) << QByteArray() << 0 << QDateTime() << 0; - - QByteArray data( " \"28-May-2006 01:03:35 +0200\"" ); - QDateTime dt( QDate( 2006, 5, 27 ), QTime( 23, 3, 35 ), Qt::UTC ); - QTest::newRow( "quoted 1" ) << data << 0 << dt << 29; - QTest::newRow( "quoted 2" ) << data << 1 << dt << 29; - QTest::newRow( "unquoted" ) << data << 2 << dt << 28; - QTest::newRow( "invalid" ) << data << 4 << QDateTime() << 4; -} - -void ImapParserTest::testParseDateTime() -{ - QFETCH( QByteArray, data ); - QFETCH( int, begin ); - QFETCH( QDateTime, result ); - QFETCH( int, end ); - - QDateTime actualResult; - int actualEnd = ImapParser::parseDateTime( data, actualResult, begin ); - QCOMPARE( actualResult, result ); - QCOMPARE( actualEnd, end ); -} - -void ImapParserTest::testBulkParser_data() -{ - QTest::addColumn( "input" ); - QTest::addColumn( "data" ); - - QTest::newRow( "empty" ) << QByteArray( "* PRE {0} POST\n" ) << QByteArray("PRE {0} POST\n"); - QTest::newRow( "small block" ) << QByteArray( "* PRE {2}\nXX POST\n" ) - << QByteArray( "PRE {2}\nXX POST\n" ); - QTest::newRow( "small block 2" ) << QByteArray( "* (PRE {2}\nXX\n POST)\n" ) - << QByteArray( "(PRE {2}\nXX\n POST)\n" ); - QTest::newRow( "large block" ) << QByteArray( "* PRE {10}\n0123456789\n" ) - << QByteArray( "PRE {10}\n0123456789\n" ); - QTest::newRow( "store failure" ) << QByteArray( "3 UID STORE (FOO bar ENV {3}\n(a) HEAD {3}\na\n\n BODY {3}\nabc)\n" ) - << QByteArray( "UID STORE (FOO bar ENV {3}\n(a) HEAD {3}\na\n\n BODY {3}\nabc)\n" ); -} - -void ImapParserTest::testBulkParser() -{ - QFETCH( QByteArray, input ); - QFETCH( QByteArray, data ); - - ImapParser *parser = new ImapParser(); - QBuffer buffer; - buffer.setData( input ); - QVERIFY( buffer.open( QBuffer::ReadOnly ) ); - - // reading continuation as a single block - forever { - if ( buffer.atEnd() ) - break; - if ( parser->continuationSize() > 0 ) { - parser->parseBlock( buffer.read( parser->continuationSize() ) ); - } else if ( buffer.canReadLine() ) { - const QByteArray line = buffer.readLine(); - bool res = parser->parseNextLine( line ); - QCOMPARE( res, buffer.atEnd() ); - } - } - QCOMPARE( parser->data(), data ); - - // reading continuations as smaller blocks - buffer.reset(); - parser->reset(); - forever { - if ( buffer.atEnd() ) - break; - if ( parser->continuationSize() > 4 ) { - parser->parseBlock( buffer.read( 4 ) ); - } else if ( parser->continuationSize() > 0 ) { - parser->parseBlock( buffer.read( parser->continuationSize() ) ); - } else if ( buffer.canReadLine() ) { - bool res = parser->parseNextLine( buffer.readLine() ); - QCOMPARE( res, buffer.atEnd() ); - } - } - - delete parser; -} - -#include "imapparsertest.moc" diff --git a/akonadi/tests/imapparsertest.h b/akonadi/tests/imapparsertest.h deleted file mode 100644 index 5b995c6d1..000000000 --- a/akonadi/tests/imapparsertest.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef IMAPPARSER_TEST_H -#define IMAPPARSER_TEST_H - -#include - -class ImapParserTest : public QObject -{ - Q_OBJECT - private Q_SLOTS: - void testStripLeadingSpaces(); - void testParseQuotedString(); - void testParseString(); - void testParseParenthesizedList(); - void testParseNumber(); - void testQuote_data(); - void testQuote(); - void testMessageParser_data(); - void testMessageParser(); - void testParseSequenceSet_data(); - void testParseSequenceSet(); - void testParseDateTime_data(); - void testParseDateTime(); - void testBulkParser_data(); - void testBulkParser(); -}; - - -#endif diff --git a/akonadi/tests/imapsettest.cpp b/akonadi/tests/imapsettest.cpp deleted file mode 100644 index 21faeee8a..000000000 --- a/akonadi/tests/imapsettest.cpp +++ /dev/null @@ -1,77 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "imapsettest.h" -#include "imapsettest.moc" -#include - -#include - -QTEST_KDEMAIN( ImapSetTest, NoGUI ) - -Q_DECLARE_METATYPE( QList ) - -using namespace Akonadi; - -void ImapSetTest::testAddList_data() -{ - QTest::addColumn >( "source" ); - QTest::addColumn( "intervals" ); - QTest::addColumn( "seqset" ); - - // empty set - QList source; - ImapInterval::List intervals; - QTest::newRow( "empty" ) << source << intervals << QByteArray(); - - // single value - source << 4; - intervals << ImapInterval( 4, 4 ); - QTest::newRow( "single value" ) << source << intervals << QByteArray( "4" ); - - // single 2-value interval - source << 5; - intervals.clear(); - intervals << ImapInterval( 4, 5 ); - QTest::newRow( "single 2 interval" ) << source << intervals << QByteArray( "4:5" ); - - // single large interval - source << 6 << 3 << 7 << 2 << 8; - intervals.clear(); - intervals << ImapInterval( 2, 8 ); - QTest::newRow( "single 7 interval" ) << source << intervals << QByteArray( "2:8" ); - - // double interval - source << 12; - intervals << ImapInterval( 12, 12 ); - QTest::newRow( "double interval" ) << source << intervals << QByteArray( "2:8,12" ); -} - -void ImapSetTest::testAddList() -{ - QFETCH( QList, source ); - QFETCH( ImapInterval::List, intervals ); - QFETCH( QByteArray, seqset ); - - ImapSet set; - set.add( source ); - ImapInterval::List result = set.intervals(); - QCOMPARE( result, intervals ); - QCOMPARE( set.toImapSequenceSet(), seqset ); -} diff --git a/akonadi/tests/imapsettest.h b/akonadi/tests/imapsettest.h deleted file mode 100644 index 9713e46ee..000000000 --- a/akonadi/tests/imapsettest.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_IMAPSETTEST_H -#define AKONADI_IMAPSETTEST_H - -#include - -class ImapSetTest : public QObject -{ - Q_OBJECT - private slots: - void testAddList_data(); - void testAddList(); -}; - - -#endif diff --git a/akonadi/tests/itemappendtest.cpp b/akonadi/tests/itemappendtest.cpp deleted file mode 100644 index eeff51df6..000000000 --- a/akonadi/tests/itemappendtest.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "control.h" -#include "itemappendtest.h" -#include "collectionpathresolver_p.h" -#include "testattribute.h" - -#include -#include -#include -#include -#include -#include - -#include - -using namespace Akonadi; - -#include - -QTEST_KDEMAIN( ItemAppendTest, NoGUI ) - -static Collection testFolder1; - -void ItemAppendTest::initTestCase() -{ - Control::start(); - - // get the collections we run the tests on - CollectionFetchJob *job = new CollectionFetchJob( Collection::root(), CollectionFetchJob::Recursive ); - QVERIFY( job->exec() ); - Collection::List list = job->collections(); - Collection res2; - foreach ( const Collection &col, list ) - if ( col.name() == "res2" ) - res2 = col; - foreach ( const Collection &col, list ) - if ( col.name() == "space folder" && col.parent() == res2.id() ) - testFolder1 = col; -} - -void ItemAppendTest::testItemAppend_data() -{ - QTest::addColumn( "remoteId" ); - - QTest::newRow( "empty" ) << QString(); - QTest::newRow( "non empty" ) << QString( "remote-id" ); - QTest::newRow( "whitespace" ) << QString( "remote id" ); - QTest::newRow( "quotes" ) << QString ( "\"remote\" id" ); -} - -void ItemAppendTest::testItemAppend() -{ - QFETCH( QString, remoteId ); - Item ref; // for cleanup - - Item item( -1 ); - item.setRemoteId( remoteId ); - item.setMimeType( "application/octet-stream" ); - ItemCreateJob *job = new ItemCreateJob( item, Collection( testFolder1 ), this ); - QVERIFY( job->exec() ); - ref = job->item(); - - ItemFetchJob *fjob = new ItemFetchJob( testFolder1, this ); - QVERIFY( fjob->exec() ); - QCOMPARE( fjob->items().count(), 1 ); - QCOMPARE( fjob->items()[0], ref ); - QCOMPARE( fjob->items()[0].remoteId(), remoteId ); - - ItemDeleteJob *djob = new ItemDeleteJob( ref, this ); - QVERIFY( djob->exec() ); - - fjob = new ItemFetchJob( testFolder1, this ); - QVERIFY( fjob->exec() ); - QVERIFY( fjob->items().isEmpty() ); -} - -void ItemAppendTest::testContent_data() -{ - QTest::addColumn( "data" ); - - QTest::newRow( "empty" ) << QByteArray(); - QString utf8string = QString::fromUtf8("äöüß@€µøđ¢©®"); - QTest::newRow( "utf8" ) << utf8string.toUtf8(); - QTest::newRow( "newlines" ) << QByteArray("\nsome\n\nbreaked\ncontent\n\n"); -} - -void ItemAppendTest::testContent() -{ - QFETCH( QByteArray, data ); - - Item item; - item.setMimeType( "application/octet-stream" ); - item.setPayload( data ); - - ItemCreateJob* job = new ItemCreateJob( item, Collection( testFolder1 ), this ); - QVERIFY( job->exec() ); - Item ref = job->item(); - - ItemFetchJob *fjob = new ItemFetchJob( testFolder1, this ); - fjob->fetchScope().fetchFullPayload(); - QVERIFY( fjob->exec() ); - QCOMPARE( fjob->items().count(), 1 ); - Item item2 = fjob->items().first(); - QCOMPARE( data, item2.payload() ); - - ItemDeleteJob *djob = new ItemDeleteJob( ref, this ); - QVERIFY( djob->exec() ); -} - -void ItemAppendTest::testIllegalAppend() -{ - Item item; - item.setMimeType( "application/octet-stream" ); - - // adding item to non-existing collection - ItemCreateJob *job = new ItemCreateJob( item, Collection( INT_MAX ), this ); - QVERIFY( !job->exec() ); - - // adding item with non-existing mimetype - Item item2; - item2.setMimeType( "wrong/type" ); - job = new ItemCreateJob( item2, Collection( testFolder1 ), this ); - QVERIFY( !job->exec() ); - - // adding item into a collection which can't handle items of this type - CollectionPathResolver *resolver = new CollectionPathResolver( "res1/foo/bla", this ); - QVERIFY( resolver->exec() ); - const Collection col = Collection( resolver->collection() ); - job = new ItemCreateJob( item, col, this ); - QEXPECT_FAIL( "", "Test not yet implemented in the server.", Continue ); - QVERIFY( !job->exec() ); -} - -void ItemAppendTest::testMultipartAppend() -{ - AttributeFactory::registerAttribute(); - - Item item; - item.setMimeType( "application/octet-stream" ); - item.setPayload( "body data" ); - item.attribute( Item::AddIfMissing )->data = "extra data"; - ItemCreateJob *job = new ItemCreateJob( item, Collection( testFolder1 ), this ); - QVERIFY( job->exec() ); - Item ref = job->item(); - - ItemFetchJob *fjob = new ItemFetchJob( ref, this ); - fjob->fetchScope().fetchFullPayload(); - fjob->fetchScope().fetchAttribute(); - QVERIFY( fjob->exec() ); - QCOMPARE( fjob->items().count(), 1 ); - item = fjob->items().first(); - QCOMPARE( item.payload(), QByteArray( "body data" ) ); - QVERIFY( item.hasAttribute() ); - QCOMPARE( item.attribute()->data, QByteArray( "extra data" ) ); - - ItemDeleteJob *djob = new ItemDeleteJob( ref, this ); - QVERIFY( djob->exec() ); -} - -#include "itemappendtest.moc" diff --git a/akonadi/tests/itemappendtest.h b/akonadi/tests/itemappendtest.h deleted file mode 100644 index d8ec933b6..000000000 --- a/akonadi/tests/itemappendtest.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef ITEMAPPENDTEST_H -#define ITEMAPPENDTEST_H - -#include - -class ItemAppendTest : public QObject -{ - Q_OBJECT - private Q_SLOTS: - void initTestCase(); - void testItemAppend_data(); - void testItemAppend(); - void testContent_data(); - void testContent(); - void testIllegalAppend(); - void testMultipartAppend(); -}; - - -#endif diff --git a/akonadi/tests/itemcopytest.cpp b/akonadi/tests/itemcopytest.cpp deleted file mode 100644 index 8bad227f6..000000000 --- a/akonadi/tests/itemcopytest.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include -#include -#include -#include -#include - -#include - -#include - -using namespace Akonadi; - -class ItemCopyTest : public QObject -{ - Q_OBJECT - private slots: - void initTestCase() - { - Control::start(); - } - - void testCopy() - { - const Collection target( 8 ); - Item item( 1 ); - - ItemCopyJob *copy = new ItemCopyJob( item, target ); - QVERIFY( copy->exec() ); - - ItemFetchJob *fetch = new ItemFetchJob( target ); - fetch->fetchScope().fetchFullPayload(); - fetch->fetchScope().fetchAllAttributes(); - QVERIFY( fetch->exec() ); - QCOMPARE( fetch->items().count(), 1 ); - } - - void testIlleagalCopy() - { - // empty item list - ItemCopyJob *copy = new ItemCopyJob( Item::List(), Collection::root() ); - QVERIFY( !copy->exec() ); - - // non-existing target - copy = new ItemCopyJob( Item( 1 ), Collection( INT_MAX ) ); - QVERIFY( !copy->exec() ); - - // non-existing source - copy = new ItemCopyJob( Item( INT_MAX ), Collection::root() ); - QVERIFY( !copy->exec() ); - } - -}; - -QTEST_KDEMAIN( ItemCopyTest, NoGUI ) - -#include "itemcopytest.moc" diff --git a/akonadi/tests/itemdumper.cpp b/akonadi/tests/itemdumper.cpp deleted file mode 100644 index 250f7047a..000000000 --- a/akonadi/tests/itemdumper.cpp +++ /dev/null @@ -1,104 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - Copyright (c) 2007 Robert Zwerus - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "itemdumper.h" -#include "collectionpathresolver_p.h" - -#include - -#include -#include -#include - -#include -#include - -#include -#include - -#define GLOBAL_TRANSACTION 1 - -using namespace Akonadi; - -ItemDumper::ItemDumper( const QString &path, const QString &filename, const QString &mimetype, int count ) : - mJobCount( 0 ) -{ - CollectionPathResolver* resolver = new CollectionPathResolver( path, this ); - Q_ASSERT( resolver->exec() ); - const Collection collection = Collection( resolver->collection() ); - - QFile f( filename ); - Q_ASSERT( f.open(QIODevice::ReadOnly) ); - QByteArray data = f.readAll(); - f.close(); - Item item; - item.setMimeType( mimetype ); - item.setPayloadFromData( data ); - mTime.start(); -#ifdef GLOBAL_TRANSACTION - TransactionBeginJob *begin = new TransactionBeginJob( this ); - connect( begin, SIGNAL(result(KJob*)), SLOT(done(KJob*)) ); - ++mJobCount; -#endif - for ( int i = 0; i < count; ++i ) { - ++mJobCount; - ItemCreateJob *job = new ItemCreateJob( item, collection, this ); - connect( job, SIGNAL(result(KJob*)), SLOT(done(KJob*)) ); - } -#ifdef GLOBAL_TRANSACTION - TransactionCommitJob *commit = new TransactionCommitJob( this ); - connect( commit, SIGNAL(result(KJob*)), SLOT(done(KJob*)) ); - ++mJobCount; -#endif -} - -void ItemDumper::done( KJob * job ) -{ - --mJobCount; - if ( job->error() ) { - qWarning() << "Error while creating item: " << job->errorString(); - } - if ( mJobCount <= 0 ) { - qDebug() << "Time:" << mTime.elapsed() << "ms"; - qApp->quit(); - } -} - -int main( int argc, char** argv ) -{ - KCmdLineArgs::init( argc, argv, "test", 0, ki18n("Test") ,"1.0" ,ki18n("test app") ); - - KCmdLineOptions options; - options.add("path ", ki18n("IMAP destination path")); - options.add("mimetype ", ki18n("Source mimetype"), "application/octet-stream"); - options.add("file ", ki18n("Source file")); - options.add("count ", ki18n("Number of times this file is added"), "1"); - KCmdLineArgs::addCmdLineOptions( options ); - KApplication app; - KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); - QString path = args->getOption( "path" ); - QString mimetype = args->getOption( "mimetype" ); - QString file = args->getOption( "file" ); - int count = qMax( 1, args->getOption( "count").toInt() ); - ItemDumper d( path, file, mimetype, count ); - return app.exec(); -} - -#include "itemdumper.moc" diff --git a/akonadi/tests/itemdumper.h b/akonadi/tests/itemdumper.h deleted file mode 100644 index 168b1342e..000000000 --- a/akonadi/tests/itemdumper.h +++ /dev/null @@ -1,48 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - Copyright (c) 2007 Robert Zwerus - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef ITEMDUMPER_H -#define ITEMDUMPER_H - -#include - -#include - -class KJob; - -class ItemDumper : public QObject -{ - Q_OBJECT - public: - ItemDumper( const QString &path, const QString &filename, const QString &mimetype, int count ); - - private Q_SLOTS: - void done(KJob* job); - - private: - QTime mTime; - int mJobCount; - -}; - - - - -#endif diff --git a/akonadi/tests/itemfetchtest.cpp b/akonadi/tests/itemfetchtest.cpp deleted file mode 100644 index c98e452a6..000000000 --- a/akonadi/tests/itemfetchtest.cpp +++ /dev/null @@ -1,199 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "itemfetchtest.h" -#include "itemfetchtest.moc" -#include "collectionpathresolver_p.h" -#include "testattribute.h" - -#include -#include -#include -#include -#include - -using namespace Akonadi; - -#include - -QTEST_KDEMAIN( ItemFetchTest, NoGUI ) - -void ItemFetchTest::initTestCase() -{ - qRegisterMetaType(); - AttributeFactory::registerAttribute(); -} - -void ItemFetchTest::testFetch() -{ - CollectionPathResolver *resolver = new CollectionPathResolver( "res1", this ); - QVERIFY( resolver->exec() ); - int colId = resolver->collection(); - - // listing of an empty folder - ItemFetchJob *job = new ItemFetchJob( Collection( colId ), this ); - QVERIFY( job->exec() ); - QVERIFY( job->items().isEmpty() ); - - resolver = new CollectionPathResolver( "res1/foo", this ); - QVERIFY( resolver->exec() ); - int colId2 = resolver->collection(); - - // listing of a non-empty folder - job = new ItemFetchJob( Collection( colId2 ), this ); - QSignalSpy spy( job, SIGNAL(itemsReceived(Akonadi::Item::List)) ); - QVERIFY( spy.isValid() ); - QVERIFY( job->exec() ); - Item::List items = job->items(); - QCOMPARE( items.count(), 15 ); - - int count = 0; - for ( int i = 0; i < spy.count(); ++i ) { - Item::List l = spy[i][0].value(); - for ( int j = 0; j < l.count(); ++j ) { - QVERIFY( items.count() > count + j ); - QCOMPARE( items[count + j], l[j] ); - } - count += l.count(); - } - QCOMPARE( count, items.count() ); - - // check if the fetch response is parsed correctly - Item item = items[0]; - QCOMPARE( item.remoteId(), QString( "A" ) ); - - QCOMPARE( item.flags().count(), 3 ); - QVERIFY( item.hasFlag( "\\Seen" ) ); - QVERIFY( item.hasFlag( "\\Flagged" ) ); - QVERIFY( item.hasFlag( "\\Draft" ) ); - - item = items[1]; - QCOMPARE( item.flags().count(), 1 ); - QVERIFY( item.hasFlag( "\\Flagged" ) ); - - item = items[2]; - QVERIFY( item.flags().isEmpty() ); -} - -void ItemFetchTest::testIllegalFetch() -{ - // fetch non-existing folder - ItemFetchJob *job = new ItemFetchJob( Collection( INT_MAX ), this ); - QVERIFY( !job->exec() ); - - // listing of root - job = new ItemFetchJob( Collection::root(), this ); - QVERIFY( !job->exec() ); - - // fetch a non-existing message - job = new ItemFetchJob( Item( INT_MAX ), this ); - QVERIFY( job->exec() ); - QVERIFY( job->items().isEmpty() ); - - // fetch message with empty reference - job = new ItemFetchJob( Item(), this ); - QVERIFY( !job->exec() ); -} - -void ItemFetchTest::testMultipartFetch_data() -{ - QTest::addColumn( "fetchFullPayload" ); - QTest::addColumn( "fetchAllAttrs" ); - QTest::addColumn( "fetchSinglePayload" ); - QTest::addColumn( "fetchSingleAttr" ); - - QTest::newRow( "empty" ) << false << false << false << false; - QTest::newRow( "full" ) << true << true << false << false; - QTest::newRow( "full payload" ) << true << false << false << false; - QTest::newRow( "single payload" ) << false << false << true << false; - QTest::newRow( "single" ) << false << false << true << true; - QTest::newRow( "attr full" ) << false << true << false << false; - QTest::newRow( "attr single" ) << false << false << false << true; - QTest::newRow( "mixed cross 1" ) << true << false << false << true; - QTest::newRow( "mixed cross 2" ) << false << true << true << false; - QTest::newRow( "all" ) << true << true << true << true; - QTest::newRow( "all payload" ) << true << false << true << false; - QTest::newRow( "all attr" ) << false << true << true << false; -} - -void ItemFetchTest::testMultipartFetch() -{ - QFETCH( bool, fetchFullPayload ); - QFETCH( bool, fetchAllAttrs ); - QFETCH( bool, fetchSinglePayload ); - QFETCH( bool, fetchSingleAttr ); - - CollectionPathResolver *resolver = new CollectionPathResolver( "res1/foo", this ); - QVERIFY( resolver->exec() ); - int colId = resolver->collection(); - - Item item; - item.setMimeType( "application/octet-stream" ); - item.setPayload( "body data" ); - item.attribute( Item::AddIfMissing )->data = "extra data"; - ItemCreateJob *job = new ItemCreateJob( item, Collection( colId ), this ); - QVERIFY( job->exec() ); - Item ref = job->item(); - - ItemFetchJob *fjob = new ItemFetchJob( ref, this ); - if ( fetchFullPayload ) - fjob->fetchScope().fetchFullPayload(); - if ( fetchAllAttrs ) - fjob->fetchScope().fetchAttribute(); - if ( fetchSinglePayload ) - fjob->fetchScope().fetchPayloadPart( Item::FullPayload ); - if ( fetchSingleAttr ) - fjob->fetchScope().fetchAttribute(); - - QVERIFY( fjob->exec() ); - QCOMPARE( fjob->items().count(), 1 ); - item = fjob->items().first(); - - if ( fetchFullPayload || fetchSinglePayload ) { - QCOMPARE( item.loadedPayloadParts().count(), 1 ); - QVERIFY( item.hasPayload() ); - QCOMPARE( item.payload(), QByteArray( "body data" ) ); - } else { - QCOMPARE( item.loadedPayloadParts().count(), 0 ); - QVERIFY( !item.hasPayload() ); - } - - if ( fetchAllAttrs || fetchSingleAttr ) { - QCOMPARE( item.attributes().count(), 1 ); - QVERIFY( item.hasAttribute() ); - QCOMPARE( item.attribute()->data, QByteArray( "extra data" ) ); - } else { - QCOMPARE( item.attributes().count(), 0 ); - } - - // cleanup - ItemDeleteJob *djob = new ItemDeleteJob( ref, this ); - QVERIFY( djob->exec() ); -} - -void ItemFetchTest::testVirtualFetch() -{ - CollectionPathResolver *resolver = new CollectionPathResolver( "Search/kde-core-devel", this ); - QVERIFY( resolver->exec() ); - Collection col = Collection( resolver->collection() ); - - ItemFetchJob *job = new ItemFetchJob( col, this ); - QVERIFY( job->exec() ); - QCOMPARE( job->items().count(), 3 ); -} diff --git a/akonadi/tests/itemfetchtest.h b/akonadi/tests/itemfetchtest.h deleted file mode 100644 index 2075231ba..000000000 --- a/akonadi/tests/itemfetchtest.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef ITEMFETCHTEST_H -#define ITEMFETCHTEST_H - -#include - -class ItemFetchTest : public QObject -{ - Q_OBJECT - private slots: - void initTestCase(); - void testFetch(); - void testIllegalFetch(); - void testMultipartFetch_data(); - void testMultipartFetch(); - void testVirtualFetch(); -}; - - -#endif diff --git a/akonadi/tests/itemhydratest.cpp b/akonadi/tests/itemhydratest.cpp deleted file mode 100644 index 0bae0178f..000000000 --- a/akonadi/tests/itemhydratest.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/* - Copyright (c) 2006 Till Adam - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "itemhydratest.h" - -#include -#include -#include -#include -#include -#include - -using namespace Akonadi; -using boost::shared_ptr; - -struct Volker -{ - bool operator==( const Volker& f ) const - { - return f.who == who; - } - virtual ~Volker() { } - QString who; -}; -typedef shared_ptr VolkerPtr; - -struct Rudi: public Volker -{ - Rudi() { who = "Rudi"; } - virtual ~Rudi() { } -}; - -typedef shared_ptr RudiPtr; - -struct Gerd: public Volker -{ - Gerd() { who = "Gerd"; } -}; - - -QTEST_KDEMAIN( ItemHydra, NoGUI ) - -ItemHydra::ItemHydra() -{ -} - -void ItemHydra::initTestCase() -{ -} - - -void ItemHydra::testItemValuePayload() -{ - Item f; - Rudi rudi; - f.setPayload( rudi ); - QVERIFY( f.hasPayload() ); - - Item b; - Gerd gerd; - b.setPayload( gerd ); - QVERIFY( b.hasPayload() ); - - QCOMPARE( f.payload(), rudi ); - QVERIFY( !(f.payload() == gerd ) ); - QCOMPARE( b.payload(), gerd); - QVERIFY( !(b.payload() == rudi) ); -} - -void ItemHydra::testItemPointerPayload() -{ - Item f; - Rudi *rudi = new Rudi; - - // the below should assert - //f.setPayload( rudi ); - - f.setPayload( std::auto_ptr( rudi ) ); - QVERIFY( f.hasPayload() ); - QCOMPARE( f.payload< std::auto_ptr >()->who, rudi->who ); - - // below doesn't compile, hopefully - //QCOMPARE( f.payload< Rudi* >()->who, rudi->who ); -} - -void ItemHydra::testItemCopy() -{ - Item f; - Rudi rudi; - f.setPayload( rudi ); - - Item r = f; - QCOMPARE( r.payload(), rudi ); - - Item s; - s = f; - QVERIFY( s.hasPayload() ); - QCOMPARE( s.payload(), rudi ); - -} - -void ItemHydra::testEmptyPayload() -{ - Item i1; - Item i2; - i1 = i2; // should not crash - - QVERIFY( !i1.hasPayload() ); - QVERIFY( !i2.hasPayload() ); -} - -void ItemHydra::testPointerPayload() -{ - Rudi* r = new Rudi; - RudiPtr p( r ); - boost::weak_ptr w( p ); - QCOMPARE( p.use_count(), (long)1 ); - - { - Item i1; - i1.setPayload(p); - QVERIFY( i1.hasPayload() ); - QCOMPARE( p.use_count(), (long)2 ); - { - RudiPtr p2 = i1.payload< RudiPtr >(); - QCOMPARE( p.use_count(), (long)3 ); - } - QCOMPARE( p.use_count(), (long)2 ); - } - QCOMPARE( p.use_count(), (long)1 ); - QCOMPARE( w.use_count(), (long)1 ); - p.reset(); - QCOMPARE( w.use_count(), (long)0 ); -} - - -void ItemHydra::testPolymorphicPayload() -{ - VolkerPtr p( new Rudi ); - - { - Item i1; - i1.setPayload(p); - QVERIFY( i1.hasPayload() ); - QCOMPARE( p.use_count(), (long)2 ); - { - RudiPtr p2 = boost::dynamic_pointer_cast( i1.payload< VolkerPtr >() ); - QCOMPARE( p.use_count(), (long)3 ); - QCOMPARE( p2->who, QString("Rudi") ); - } - QCOMPARE( p.use_count(), (long)2 ); - } -} - -void ItemHydra::testHasPayload() -{ - Item i1; - QVERIFY( !i1.hasPayload() ); - QVERIFY( !i1.hasPayload() ); - - Rudi r; - i1.setPayload( r ); - QVERIFY( i1.hasPayload() ); - QVERIFY( !i1.hasPayload() ); -} - -#include "itemhydratest.moc" diff --git a/akonadi/tests/itemhydratest.h b/akonadi/tests/itemhydratest.h deleted file mode 100644 index 98a3a48d4..000000000 --- a/akonadi/tests/itemhydratest.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - Copyright (c) 2007 Till Adam - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef ITEMHYDRA_H -#define ITEMHYDRA_H - -#include - -class ItemHydra: public QObject -{ - Q_OBJECT - public: - ItemHydra(); - virtual ~ItemHydra() { } - private Q_SLOTS: - void initTestCase(); - void testItemValuePayload(); - void testItemPointerPayload(); - void testItemCopy(); - void testEmptyPayload(); - void testPointerPayload(); - void testPolymorphicPayload(); - void testHasPayload(); -}; - -#endif diff --git a/akonadi/tests/itemserializertest.cpp b/akonadi/tests/itemserializertest.cpp deleted file mode 100644 index 98b78327a..000000000 --- a/akonadi/tests/itemserializertest.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "itemserializertest.h" - -#include -#include -#include - -#include - -using namespace Akonadi; - -QTEST_KDEMAIN( ItemSerializerTest, NoGUI ) - -void ItemSerializerTest::testEmptyPayload() -{ - // should not crash - QByteArray data; - Item item; - ItemSerializer::deserialize( item, Item::FullPayload, data, 0 ); - QVERIFY( data.isEmpty() ); -} - -void ItemSerializerTest::testDefaultSerializer() -{ - QByteArray serialized = "\0\r\n\0bla"; - Item item; - item.setMimeType( "application/octet-stream" ); - ItemSerializer::deserialize( item, Item::FullPayload, serialized, 0 ); - - QVERIFY( item.hasPayload() ); - QCOMPARE( item.payload(), serialized ); - - QByteArray data; - int version = 0; - ItemSerializer::serialize( item, Item::FullPayload, data, version ); - QCOMPARE( serialized, data ); -} - -#include "itemserializertest.moc" diff --git a/akonadi/tests/itemserializertest.h b/akonadi/tests/itemserializertest.h deleted file mode 100644 index ab5f9ad35..000000000 --- a/akonadi/tests/itemserializertest.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef ITEMSERIALIZERTEST_H -#define ITEMSERIALIZERTEST_H - -#include - -class ItemSerializerTest : public QObject -{ - Q_OBJECT - private slots: - void testEmptyPayload(); - void testDefaultSerializer(); -}; - - -#endif diff --git a/akonadi/tests/itemstoretest.cpp b/akonadi/tests/itemstoretest.cpp deleted file mode 100644 index 60cc6ab2d..000000000 --- a/akonadi/tests/itemstoretest.cpp +++ /dev/null @@ -1,325 +0,0 @@ - /* - Copyright (c) 2006 Volker Krause - Copyright (c) 2007 Robert Zwerus - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "control.h" -#include "itemstoretest.h" -#include "testattribute.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace Akonadi; - -QTEST_KDEMAIN( ItemStoreTest, NoGUI ) - -static Collection res1_foo; -static Collection res2; -static Collection res3; - -void ItemStoreTest::initTestCase() -{ - Control::start(); - AttributeFactory::registerAttribute(); - - // get the collections we run the tests on - CollectionFetchJob *job = new CollectionFetchJob( Collection::root(), CollectionFetchJob::Recursive ); - QVERIFY( job->exec() ); - Collection::List list = job->collections(); - Collection res1; - foreach ( const Collection &col, list ) { - if ( col.name() == "res1" ) - res1 = col; - if ( col.name() == "res2" ) - res2 = col; - if ( col.name() == "res3" ) - res3 = col; - } - foreach ( const Collection &col, list ) { - if ( col.name() == "foo" && col.parent() == res1.id() ) - res1_foo = col; - } -} - -void ItemStoreTest::testFlagChange() -{ - ItemFetchJob *fjob = new ItemFetchJob( Item( 1 ) ); - QVERIFY( fjob->exec() ); - QCOMPARE( fjob->items().count(), 1 ); - Item item = fjob->items()[0]; - - // add a flag - Item::Flags origFlags = item.flags(); - Item::Flags expectedFlags = origFlags; - expectedFlags.insert( "added_test_flag_1" ); - item.setFlag( "added_test_flag_1" ); - ItemModifyJob *sjob = new ItemModifyJob( item, this ); - QVERIFY( sjob->exec() ); - - fjob = new ItemFetchJob( Item( 1 ) ); - QVERIFY( fjob->exec() ); - QCOMPARE( fjob->items().count(), 1 ); - item = fjob->items()[0]; - QCOMPARE( item.flags().count(), expectedFlags.count() ); - Item::Flags diff = expectedFlags - item.flags(); - QVERIFY( diff.isEmpty() ); - - // set flags - expectedFlags.insert( "added_test_flag_2" ); - item.setFlags( expectedFlags ); - sjob = new ItemModifyJob( item, this ); - QVERIFY( sjob->exec() ); - - fjob = new ItemFetchJob( Item( 1 ) ); - QVERIFY( fjob->exec() ); - QCOMPARE( fjob->items().count(), 1 ); - item = fjob->items()[0]; - QCOMPARE( item.flags().count(), expectedFlags.count() ); - diff = expectedFlags - item.flags(); - QVERIFY( diff.isEmpty() ); - - // remove a flag - item.clearFlag( "added_test_flag_1" ); - item.clearFlag( "added_test_flag_2" ); - sjob = new ItemModifyJob( item, this ); - QVERIFY( sjob->exec() ); - - fjob = new ItemFetchJob( Item( 1 ) ); - QVERIFY( fjob->exec() ); - QCOMPARE( fjob->items().count(), 1 ); - item = fjob->items()[0]; - QCOMPARE( item.flags().count(), origFlags.count() ); - diff = origFlags - item.flags(); - QVERIFY( diff.isEmpty() ); -} - -void ItemStoreTest::testDataChange_data() -{ - QTest::addColumn( "data" ); - - QTest::newRow( "empty" ) << QByteArray(); - QTest::newRow( "nullbyte" ) << QByteArray("\0" ); - QTest::newRow( "nullbyte2" ) << QByteArray( "\0X" ); - QTest::newRow( "linebreaks" ) << QByteArray( "line1\nline2\n\rline3\rline4\r\n" ); - QTest::newRow( "linebreaks2" ) << QByteArray( "line1\r\nline2\r\n\r\n" ); - QTest::newRow( "linebreaks3" ) << QByteArray( "line1\nline2" ); - QTest::newRow( "simple" ) << QByteArray( "testbody" ); -} - -void ItemStoreTest::testDataChange() -{ - QFETCH( QByteArray, data ); - - Item item; - ItemFetchJob *prefetchjob = new ItemFetchJob( Item( 1 ) ); - prefetchjob->exec(); - item = prefetchjob->items()[0]; - item.setMimeType( "application/octet-stream" ); - item.setPayload( data ); - - // delete data - ItemModifyJob *sjob = new ItemModifyJob( item ); - QVERIFY( sjob->exec() ); - - ItemFetchJob *fjob = new ItemFetchJob( Item( 1 ) ); - fjob->fetchScope().fetchFullPayload(); - QVERIFY( fjob->exec() ); - QCOMPARE( fjob->items().count(), 1 ); - item = fjob->items()[0]; - QVERIFY( item.hasPayload() ); - QCOMPARE( item.payload(), data ); -} - -void ItemStoreTest::testItemMove() -{ - ItemFetchJob *prefetchjob = new ItemFetchJob( Item( 1 ) ); - prefetchjob->exec(); - Item item = prefetchjob->items()[0]; - - ItemMoveJob *store = new ItemMoveJob( item, res3, this ); - QVERIFY( store->exec() ); - - ItemFetchJob *fetch = new ItemFetchJob( res3, this ); - QVERIFY( fetch->exec() ); - QCOMPARE( fetch->items().count(), 1 ); - - store = new ItemMoveJob( item, res1_foo, this ); - QVERIFY( store->exec() ); -} - -void ItemStoreTest::testIllegalItemMove() -{ - ItemFetchJob *prefetchjob = new ItemFetchJob( Item( 1 ) ); - prefetchjob->exec(); - Item item = prefetchjob->items()[0]; - - // move into invalid collection - ItemMoveJob *store = new ItemMoveJob( item, Collection( INT_MAX ), this ); - QVERIFY( !store->exec() ); - - // move item into folder that doesn't support its mimetype - store = new ItemMoveJob( item, res2, this ); - QEXPECT_FAIL( "", "Check not yet implemented by the server.", Continue ); - QVERIFY( !store->exec() ); -} - -void ItemStoreTest::testRemoteId_data() -{ - QTest::addColumn( "rid" ); - QTest::addColumn( "exprid" ); - - QTest::newRow( "set" ) << QString( "A" ) << QString( "A" ); - QTest::newRow( "no-change" ) << QString() << QString( "A" ); - QTest::newRow( "clear" ) << QString( "" ) << QString( "" ); - QTest::newRow( "reset" ) << QString( "A" ) << QString( "A" ); -} - -void ItemStoreTest::testRemoteId() -{ - QFETCH( QString, rid ); - QFETCH( QString, exprid ); - - ItemFetchJob *prefetchjob = new ItemFetchJob( Item( 1 ) ); - prefetchjob->exec(); - Item item = prefetchjob->items()[0]; - - item.setId( 1 ); - item.setRemoteId( rid ); - ItemModifyJob *store = new ItemModifyJob( item, this ); - QVERIFY( store->exec() ); - - ItemFetchJob *fetch = new ItemFetchJob( item, this ); - QVERIFY( fetch->exec() ); - QCOMPARE( fetch->items().count(), 1 ); - item = fetch->items().at( 0 ); - QCOMPARE( item.remoteId(), exprid ); -} - -void ItemStoreTest::testMultiPart() -{ - ItemFetchJob *prefetchjob = new ItemFetchJob( Item( 1 ) ); - prefetchjob->exec(); - Item item = prefetchjob->items()[0]; - item.setMimeType( "application/octet-stream" ); - item.setPayload( "testmailbody" ); - item.attribute( Item::AddIfMissing )->data = "extra"; - - // store item - ItemModifyJob *sjob = new ItemModifyJob( item ); - QVERIFY( sjob->exec() ); - - ItemFetchJob *fjob = new ItemFetchJob( Item( 1 ) ); - fjob->fetchScope().fetchAttribute(); - fjob->fetchScope().fetchFullPayload(); - QVERIFY( fjob->exec() ); - QCOMPARE( fjob->items().count(), 1 ); - item = fjob->items()[0]; - QCOMPARE( item.payload(), QByteArray("testmailbody") ); - QVERIFY( item.hasAttribute() ); - QCOMPARE( item.attribute()->data, QByteArray("extra") ); - - // clean up - item.removeAttribute( "EXTRA" ); - sjob = new ItemModifyJob( item ); - QVERIFY( sjob->exec() ); -} - -void ItemStoreTest::testPartRemove() -{ - ItemFetchJob *prefetchjob = new ItemFetchJob( Item( 2 ) ); - prefetchjob->exec(); - Item item = prefetchjob->items()[0]; - item.setMimeType( "application/octet-stream" ); - item.attribute( Item::AddIfMissing )->data = "extra"; - - // store item - ItemModifyJob *sjob = new ItemModifyJob( item ); - QVERIFY( sjob->exec() ); - - // fetch item and its parts (should be RFC822, HEAD and EXTRA) - ItemFetchJob *fjob = new ItemFetchJob( Item( 2 ) ); - fjob->fetchScope().fetchFullPayload(); - fjob->fetchScope().fetchAllAttributes(); - QVERIFY( fjob->exec() ); - QCOMPARE( fjob->items().count(), 1 ); - item = fjob->items()[0]; - QCOMPARE( item.attributes().count(), 2 ); - QVERIFY( item.hasAttribute() ); - - // remove a part - item.removeAttribute(); - sjob = new ItemModifyJob( item ); - QVERIFY( sjob->exec() ); - - // fetch item again (should only have RFC822 and HEAD left) - ItemFetchJob *fjob2 = new ItemFetchJob( Item( 2 ) ); - fjob2->fetchScope().fetchFullPayload(); - fjob2->fetchScope().fetchAllAttributes(); - QVERIFY( fjob2->exec() ); - QCOMPARE( fjob2->items().count(), 1 ); - item = fjob2->items()[0]; - QCOMPARE( item.attributes().count(), 1 ); - QVERIFY( !item.hasAttribute() ); -} - -void ItemStoreTest::testRevisionCheck() -{ - // make sure we don't have any other collection selected - // otherwise EXPUNGE doesn't work and will be triggered by - // the following tests and mess up the monitor testing - CollectionSelectJob *sel = new CollectionSelectJob( Collection::root(), this ); - QVERIFY( sel->exec() ); - - // fetch same item twice - Item ref( 2 ); - ItemFetchJob *prefetchjob = new ItemFetchJob( ref ); - prefetchjob->exec(); - Item item1 = prefetchjob->items()[0]; - Item item2 = prefetchjob->items()[0]; - - // store first item unmodified - ItemModifyJob *sjob = new ItemModifyJob( item1 ); - QVERIFY( sjob->exec() ); - - // try to store second item - ItemModifyJob *sjob2 = new ItemModifyJob( item2 ); - item2.attribute( Item::AddIfMissing )->data = "extra"; - QVERIFY( !sjob2->exec() ); - - // fetch same again - prefetchjob = new ItemFetchJob( ref ); - prefetchjob->exec(); - item1 = prefetchjob->items()[0]; - - // delete item - ItemDeleteJob *djob = new ItemDeleteJob( ref, this ); - djob->exec(); - - // try to store it - sjob = new ItemModifyJob( item1 ); - QVERIFY( !sjob->exec() ); -} - -#include "itemstoretest.moc" diff --git a/akonadi/tests/itemstoretest.h b/akonadi/tests/itemstoretest.h deleted file mode 100644 index 6d6be4ead..000000000 --- a/akonadi/tests/itemstoretest.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - Copyright (c) 2007 Robert Zwerus - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef ITEMSTORETEST_H -#define ITEMSTORETEST_H - -#include - -class ItemStoreTest : public QObject -{ - Q_OBJECT - private Q_SLOTS: - void initTestCase(); - void testFlagChange(); - void testDataChange_data(); - void testDataChange(); - void testItemMove(); - void testIllegalItemMove(); - void testRemoteId_data(); - void testRemoteId(); - void testMultiPart(); - void testPartRemove(); - void testRevisionCheck(); -}; - -#endif diff --git a/akonadi/tests/itemsynctest.cpp b/akonadi/tests/itemsynctest.cpp deleted file mode 100644 index 0a9e78208..000000000 --- a/akonadi/tests/itemsynctest.cpp +++ /dev/null @@ -1,155 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include - -using namespace Akonadi; - -Q_DECLARE_METATYPE( KJob* ) - -class ItemsyncTest : public QObject -{ - Q_OBJECT - private: - Item::List fetchItems() - { - ItemFetchJob *fetch = new ItemFetchJob( Collection( 10 ) ); - fetch->fetchScope().fetchFullPayload(); - fetch->fetchScope().fetchAllAttributes(); - Q_ASSERT( fetch->exec() ); - Q_ASSERT( !fetch->items().isEmpty() ); - return fetch->items(); - } - - private slots: - void initTestCase() - { - Control::start(); - qRegisterMetaType(); - } - - void testFullSync() - { - Item::List origItems = fetchItems(); - - ItemSync* syncer = new ItemSync( Collection( 10 ) ); - syncer->setFullSyncItems( origItems ); - QVERIFY( syncer->exec() ); - - Item::List resultItems = fetchItems(); - QCOMPARE( resultItems.count(), origItems.count() ); - } - - void testFullStreamingSync() - { - Item::List origItems = fetchItems(); - - ItemSync* syncer = new ItemSync( Collection( 10 ) ); - QSignalSpy spy( syncer, SIGNAL(result(KJob*)) ); - QVERIFY( spy.isValid() ); - syncer->setTotalItems( origItems.count() ); - QTest::qWait( 10 ); - QCOMPARE( spy.count(), 0 ); - - for ( int i = 0; i < origItems.count(); ++i ) { - Item::List l; - l << origItems[i]; - syncer->setFullSyncItems( l ); - if ( i < origItems.count() - 1 ) - QTest::qWait( 10 ); // enter the event loop so itemsync actually can do something - QCOMPARE( spy.count(), 0 ); - } - QTest::qWait( 1000 ); // let it finish its job - QCOMPARE( spy.count(), 1 ); - KJob *job = spy.at( 0 ).at( 0 ).value(); - QVERIFY( job ); - QCOMPARE( job->error(), 0 ); - - Item::List resultItems = fetchItems(); - QCOMPARE( resultItems.count(), origItems.count() ); - } - - void testIncrementalSync() - { - Item::List origItems = fetchItems(); - - ItemSync* syncer = new ItemSync( Collection( 10 ) ); - syncer->setIncrementalSyncItems( origItems, Item::List() ); - QVERIFY( syncer->exec() ); - - Item::List resultItems = fetchItems(); - QCOMPARE( resultItems.count(), origItems.count() ); - } - - void testIncrementalStreamingSync() - { - Item::List origItems = fetchItems(); - - ItemSync* syncer = new ItemSync( Collection( 10 ) ); - QSignalSpy spy( syncer, SIGNAL(result(KJob*)) ); - QVERIFY( spy.isValid() ); - syncer->setStreamingEnabled( true ); - QTest::qWait( 10 ); - QCOMPARE( spy.count(), 0 ); - - for ( int i = 0; i < origItems.count(); ++i ) { - Item::List l; - l << origItems[i]; - syncer->setIncrementalSyncItems( l, Item::List() ); - if ( i < origItems.count() - 1 ) - QTest::qWait( 10 ); // enter the event loop so itemsync actually can do something - QCOMPARE( spy.count(), 0 ); - } - syncer->deliveryDone(); - QTest::qWait( 1000 ); // let it finish its job - QCOMPARE( spy.count(), 1 ); - KJob *job = spy.at( 0 ).at( 0 ).value(); - QVERIFY( job ); - QCOMPARE( job->error(), 0 ); - - Item::List resultItems = fetchItems(); - QCOMPARE( resultItems.count(), origItems.count() ); - } - - void testEmptyIncrementalSync() - { - Item::List origItems = fetchItems(); - - ItemSync* syncer = new ItemSync( Collection( 10 ) ); - syncer->setIncrementalSyncItems( Item::List(), Item::List() ); - QVERIFY( syncer->exec() ); - - Item::List resultItems = fetchItems(); - QCOMPARE( resultItems.count(), origItems.count() ); - } -}; - -QTEST_KDEMAIN( ItemsyncTest, NoGUI ) - -#include "itemsynctest.moc" diff --git a/akonadi/tests/itemtest.cpp b/akonadi/tests/itemtest.cpp deleted file mode 100644 index d1256e58d..000000000 --- a/akonadi/tests/itemtest.cpp +++ /dev/null @@ -1,63 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "itemtest.h" -#include "itemtest.moc" -#include "testattribute.h" - -#include - -#include - -QTEST_KDEMAIN( ItemTest, NoGUI ) - -using namespace Akonadi; - -void ItemTest::testMultipart() -{ - Item item; - item.setMimeType( "application/octet-stream" ); - - QSet parts; - QCOMPARE( item.loadedPayloadParts(), parts ); - - QByteArray bodyData = "bodydata"; - item.setPayload( bodyData ); - parts << Item::FullPayload; - QCOMPARE( item.loadedPayloadParts(), parts ); - QCOMPARE( item.payload(), bodyData ); - - QByteArray myData = "mypartdata"; - item.attribute( Item::AddIfMissing )->data = myData; - - QCOMPARE( item.loadedPayloadParts(), parts ); - QCOMPARE( item.attributes().count(), 1 ); - QVERIFY( item.hasAttribute() ); - QCOMPARE( item.attribute()->data, myData ); -} - -void ItemTest::testInheritance() -{ - Item a; - - a.setRemoteId( "Hello World" ); - - Item b( a ); - b.setFlag( "\\send" ); -} diff --git a/akonadi/tests/itemtest.h b/akonadi/tests/itemtest.h deleted file mode 100644 index b8be110a3..000000000 --- a/akonadi/tests/itemtest.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_ITEMTEST_H -#define AKONADI_ITEMTEST_H - -#include - -class ItemTest : public QObject -{ - Q_OBJECT - private slots: - void testMultipart(); - void testInheritance(); -}; - - -#endif diff --git a/akonadi/tests/monitortest.cpp b/akonadi/tests/monitortest.cpp deleted file mode 100644 index 86f66017d..000000000 --- a/akonadi/tests/monitortest.cpp +++ /dev/null @@ -1,236 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "monitortest.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -using namespace Akonadi; - -QTEST_KDEMAIN( MonitorTest, NoGUI ) - -static Collection res3; - -Q_DECLARE_METATYPE(Akonadi::Collection::Id) - -void MonitorTest::initTestCase() -{ - Control::start(); - - // get the collections we run the tests on - CollectionFetchJob *job = new CollectionFetchJob( Collection::root(), CollectionFetchJob::Recursive ); - QVERIFY( job->exec() ); - Collection::List list = job->collections(); - foreach ( const Collection &col, list ) - if ( col.name() == "res3" ) - res3 = col; -} - -void MonitorTest::testMonitor_data() -{ - QTest::addColumn( "fetchCol" ); - QTest::newRow( "with collection fetching" ) << true; - QTest::newRow( "without collection fetching" ) << false; -} - -void MonitorTest::testMonitor() -{ - QFETCH( bool, fetchCol ); - - Monitor *monitor = new Monitor( this ); - monitor->setCollectionMonitored( Collection::root() ); - monitor->fetchCollection( fetchCol ); - monitor->itemFetchScope().fetchFullPayload(); - - // monitor signals - qRegisterMetaType(); - qRegisterMetaType(); - qRegisterMetaType(); - qRegisterMetaType(); - QSignalSpy caspy( monitor, SIGNAL(collectionAdded(Akonadi::Collection,Akonadi::Collection)) ); - QSignalSpy cmspy( monitor, SIGNAL(collectionChanged(const Akonadi::Collection&)) ); - QSignalSpy crspy( monitor, SIGNAL(collectionRemoved(const Akonadi::Collection&)) ); - QSignalSpy csspy( monitor, SIGNAL(collectionStatisticsChanged(Akonadi::Collection::Id,Akonadi::CollectionStatistics)) ); - QSignalSpy iaspy( monitor, SIGNAL(itemAdded(const Akonadi::Item&, const Akonadi::Collection&)) ); - QSignalSpy imspy( monitor, SIGNAL(itemChanged(const Akonadi::Item&, const QSet&)) ); - QSignalSpy irspy( monitor, SIGNAL(itemRemoved(const Akonadi::Item&)) ); - - QVERIFY( caspy.isValid() ); - QVERIFY( cmspy.isValid() ); - QVERIFY( crspy.isValid() ); - QVERIFY( csspy.isValid() ); - QVERIFY( iaspy.isValid() ); - QVERIFY( imspy.isValid() ); - QVERIFY( irspy.isValid() ); - - // create a collection - Collection monitorCol; - monitorCol.setParent( res3 ); - monitorCol.setName( "monitor" ); - CollectionCreateJob *create = new CollectionCreateJob( monitorCol, this ); - QVERIFY( create->exec() ); - monitorCol = create->collection(); - QVERIFY( monitorCol.isValid() ); - QTest::qWait(1000); // make sure the DBus signal has been processed - - QCOMPARE( caspy.count(), 1 ); - QList arg = caspy.takeFirst(); - Collection col = arg.at(0).value(); - QCOMPARE( col, monitorCol ); - if ( fetchCol ) - QCOMPARE( col.name(), QString("monitor") ); - Collection parent = arg.at(1).value(); - QCOMPARE( parent, res3 ); - - QVERIFY( cmspy.isEmpty() ); - QVERIFY( crspy.isEmpty() ); - QVERIFY( csspy.isEmpty() ); - QVERIFY( iaspy.isEmpty() ); - QVERIFY( imspy.isEmpty() ); - QVERIFY( irspy.isEmpty() ); - - // add an item - Item newItem; - newItem.setMimeType( "application/octet-stream" ); - ItemCreateJob *append = new ItemCreateJob( newItem, monitorCol, this ); - QVERIFY( append->exec() ); - Item monitorRef = append->item(); - QVERIFY( monitorRef.isValid() ); - QTest::qWait(1000); - - QCOMPARE( csspy.count(), 1 ); - arg = csspy.takeFirst(); - QEXPECT_FAIL( "", "Don't know how to handle 'Akonadi::Collection::Id', use qRegisterMetaType to register it. <-- I did this, but it still doesn't work!", Continue ); - QCOMPARE( arg.at(0).value(), monitorCol.id() ); - - QCOMPARE( iaspy.count(), 1 ); - arg = iaspy.takeFirst(); - Item item = arg.at( 0 ).value(); - QCOMPARE( item, monitorRef ); - QCOMPARE( item.mimeType(), QString::fromLatin1( "application/octet-stream" ) ); - Collection collection = arg.at( 1 ).value(); - QCOMPARE( collection.id(), monitorCol.id() ); - QCOMPARE( collection.remoteId(), monitorCol.remoteId() ); - - QVERIFY( caspy.isEmpty() ); - QVERIFY( cmspy.isEmpty() ); - QVERIFY( crspy.isEmpty() ); - QVERIFY( imspy.isEmpty() ); - QVERIFY( irspy.isEmpty() ); - - // modify an item - item.setPayload( "some new content" ); - ItemModifyJob *store = new ItemModifyJob( item, this ); - QVERIFY( store->exec() ); - QTest::qWait(1000); - - QCOMPARE( csspy.count(), 1 ); - arg = csspy.takeFirst(); - QEXPECT_FAIL( "", "Don't know how to handle 'Akonadi::Collection::Id', use qRegisterMetaType to register it. <-- I did this, but it still doesn't work!", Continue ); - QCOMPARE( arg.at(0).value(), monitorCol.id() ); - - QCOMPARE( imspy.count(), 1 ); - arg = imspy.takeFirst(); - item = arg.at( 0 ).value(); - QCOMPARE( monitorRef, item ); - QCOMPARE( item.payload(), QByteArray( "some new content" ) ); - - QVERIFY( caspy.isEmpty() ); - QVERIFY( cmspy.isEmpty() ); - QVERIFY( crspy.isEmpty() ); - QVERIFY( iaspy.isEmpty() ); - QVERIFY( irspy.isEmpty() ); - - // delete an item - ItemDeleteJob *del = new ItemDeleteJob( monitorRef, this ); - QVERIFY( del->exec() ); - QTest::qWait(1000); - - QCOMPARE( csspy.count(), 1 ); - arg = csspy.takeFirst(); - QEXPECT_FAIL( "", "Don't know how to handle 'Akonadi::Collection::Id', use qRegisterMetaType to register it. <-- I did this, but it still doesn't work!", Continue ); - QCOMPARE( arg.at(0).value(), monitorCol.id() ); - cmspy.clear(); - - QCOMPARE( irspy.count(), 1 ); - arg = irspy.takeFirst(); - Item ref = qvariant_cast( arg.at(0) ); - QCOMPARE( monitorRef, ref ); - - QVERIFY( caspy.isEmpty() ); - QVERIFY( cmspy.isEmpty() ); - QVERIFY( crspy.isEmpty() ); - QVERIFY( iaspy.isEmpty() ); - QVERIFY( imspy.isEmpty() ); - imspy.clear(); - - // modify a collection - monitorCol.setName( "changed name" ); - CollectionModifyJob *mod = new CollectionModifyJob( monitorCol, this ); - QVERIFY( mod->exec() ); - QTest::qWait(1000); - - QCOMPARE( cmspy.count(), 1 ); - arg = cmspy.takeFirst(); - col = arg.at(0).value(); - QCOMPARE( col, monitorCol ); - if ( fetchCol ) - QCOMPARE( col.name(), QString("changed name") ); - - QVERIFY( caspy.isEmpty() ); - QVERIFY( crspy.isEmpty() ); - QVERIFY( csspy.isEmpty() ); - QVERIFY( iaspy.isEmpty() ); - QVERIFY( imspy.isEmpty() ); - QVERIFY( irspy.isEmpty() ); - - // delete a collection - CollectionDeleteJob *cdel = new CollectionDeleteJob( monitorCol, this ); - QVERIFY( cdel->exec() ); - QTest::qWait(1000); - - QCOMPARE( crspy.count(), 1 ); - arg = crspy.takeFirst(); - QCOMPARE( arg.at(0).value().id(), monitorCol.id() ); - - QVERIFY( caspy.isEmpty() ); - QVERIFY( cmspy.isEmpty() ); - QVERIFY( csspy.isEmpty() ); - QVERIFY( iaspy.isEmpty() ); - QVERIFY( imspy.isEmpty() ); - QVERIFY( irspy.isEmpty() ); -} - -#include "monitortest.moc" diff --git a/akonadi/tests/monitortest.h b/akonadi/tests/monitortest.h deleted file mode 100644 index ee9c32e09..000000000 --- a/akonadi/tests/monitortest.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef MONITORTEST_H -#define MONITORTEST_H - -#include - -class MonitorTest : public QObject -{ - Q_OBJECT - private Q_SLOTS: - void initTestCase(); - void testMonitor_data(); - void testMonitor(); -}; - -#endif diff --git a/akonadi/tests/notificationmessagetest.cpp b/akonadi/tests/notificationmessagetest.cpp deleted file mode 100644 index 6534092c4..000000000 --- a/akonadi/tests/notificationmessagetest.cpp +++ /dev/null @@ -1,94 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "notificationmessagetest.h" -#include "notificationmessagetest.moc" - -#include - -#include - -QTEST_KDEMAIN( NotificationMessageTest, NoGUI ) - -using namespace Akonadi; - -void NotificationMessageTest::testCompress() -{ - NotificationMessage::List list; - NotificationMessage msg; - msg.setType( NotificationMessage::Item ); - msg.setOperation( NotificationMessage::Add ); - - NotificationMessage::appendAndCompress( list, msg ); - QCOMPARE( list.count(), 1 ); - - msg.setOperation( NotificationMessage::Modify ); - NotificationMessage::appendAndCompress( list, msg ); - QCOMPARE( list.count(), 1 ); - QCOMPARE( list.first().operation(), NotificationMessage::Add ); - - msg.setOperation( NotificationMessage::Remove ); - NotificationMessage::appendAndCompress( list, msg ); - QCOMPARE( list.count(), 2 ); // should be 2 for collections, 0 for items? -} - -void NotificationMessageTest::testCompress2() -{ - NotificationMessage::List list; - NotificationMessage msg; - msg.setType( NotificationMessage::Item ); - msg.setOperation( NotificationMessage::Modify ); - - NotificationMessage::appendAndCompress( list, msg ); - QCOMPARE( list.count(), 1 ); - - msg.setOperation( NotificationMessage::Remove ); - NotificationMessage::appendAndCompress( list, msg ); - QCOMPARE( list.count(), 1 ); - QCOMPARE( list.first().operation(), NotificationMessage::Remove ); -} - -void NotificationMessageTest::testCompress3() -{ - NotificationMessage::List list; - NotificationMessage msg; - msg.setType( NotificationMessage::Item ); - msg.setOperation( NotificationMessage::Modify ); - - NotificationMessage::appendAndCompress( list, msg ); - QCOMPARE( list.count(), 1 ); - - NotificationMessage::appendAndCompress( list, msg ); - QCOMPARE( list.count(), 1 ); -} - -void NotificationMessageTest::testNoCompress() -{ - NotificationMessage::List list; - NotificationMessage msg; - msg.setType( NotificationMessage::Item ); - msg.setOperation( NotificationMessage::Modify ); - - NotificationMessage::appendAndCompress( list, msg ); - QCOMPARE( list.count(), 1 ); - - msg.setType( NotificationMessage::Collection ); - NotificationMessage::appendAndCompress( list, msg ); - QCOMPARE( list.count(), 2 ); -} diff --git a/akonadi/tests/notificationmessagetest.h b/akonadi/tests/notificationmessagetest.h deleted file mode 100644 index 819b3bdfa..000000000 --- a/akonadi/tests/notificationmessagetest.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_NOTIFICATIONMESSAGETEST_H -#define AKONADI_NOTIFICATIONMESSAGETEST_H - -#include - -class NotificationMessageTest : public QObject -{ - Q_OBJECT - private slots: - void testCompress(); - void testCompress2(); - void testCompress3(); - void testNoCompress(); -}; - - -#endif diff --git a/akonadi/tests/pluginloadertest.cpp b/akonadi/tests/pluginloadertest.cpp deleted file mode 100644 index f89f911c2..000000000 --- a/akonadi/tests/pluginloadertest.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - Copyright (c) 2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "pluginloader.h" -#include "itemserializerplugin.h" - -#include -#include -#include - -#include -#include - -using namespace Akonadi; - -int main() -{ - KComponentData data( "pluginloadertest" ); - - PluginLoader *loader = PluginLoader::self(); - - const QStringList types = loader->types(); - qDebug( "Types:" ); - for ( int i = 0; i < types.count(); ++i ) - qDebug( "%s", qPrintable( types.at( i ) ) ); - - QObject *object = loader->createForName( "text/vcard" ); - if ( qobject_cast( object ) != 0 ) - qDebug( "Loaded plugin for mimetype 'text/vcard' successfully" ); - else - qDebug( "Unable to load plugin for mimetype 'text/vcard'" ); - - return 0; -} diff --git a/akonadi/tests/resourcetest.cpp b/akonadi/tests/resourcetest.cpp deleted file mode 100644 index 634d4ec38..000000000 --- a/akonadi/tests/resourcetest.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include -#include - -#include - -#include -#include - -using namespace Akonadi; - -class ResourceTest : public QObject -{ - Q_OBJECT - private slots: - void testResourceManagement() - { - qRegisterMetaType(); - QSignalSpy spyAddInstance( AgentManager::self(), SIGNAL(instanceAdded(Akonadi::AgentInstance)) ); - QVERIFY( spyAddInstance.isValid() ); - QSignalSpy spyRemoveInstance( AgentManager::self(), SIGNAL(instanceRemoved(Akonadi::AgentInstance)) ); - QVERIFY( spyRemoveInstance.isValid() ); - - AgentType type = AgentManager::self()->type( "akonadi_knut_resource" ); - QVERIFY( type.isValid() ); - - QCOMPARE( type.capabilities(), QStringList( "Resource" ) ); - - AgentInstanceCreateJob *job = new AgentInstanceCreateJob( type ); - QVERIFY( job->exec() ); - AgentInstance instance = job->instance(); - QVERIFY( instance.isValid() ); - - QTest::qWait( 2000 ); - QCOMPARE( spyAddInstance.count(), 1 ); - QCOMPARE( spyAddInstance.first().at( 0 ).value(), instance ); - QVERIFY( AgentManager::self()->instance( instance.identifier() ).isValid() ); - - job = new AgentInstanceCreateJob( type ); - QVERIFY( job->exec() ); - AgentInstance instance2 = job->instance(); - QVERIFY( !( instance == instance2 ) ); - QTest::qWait( 2000 ); - QCOMPARE( spyAddInstance.count(), 2 ); - - AgentManager::self()->removeInstance( instance ); - AgentManager::self()->removeInstance( instance2 ); - QTest::qWait( 2000 ); - QCOMPARE( spyRemoveInstance.count(), 2 ); - QVERIFY( !AgentManager::self()->instances().contains( instance ) ); - QVERIFY( !AgentManager::self()->instances().contains( instance2 ) ); - } - - void testIllegalResourceManagement() - { - AgentInstanceCreateJob *job = new AgentInstanceCreateJob( AgentManager::self()->type( "non_existing_resource" ) ); - QVERIFY( !job->exec() ); - - // unique agent - const AgentType type = AgentManager::self()->type( "akonadi_mailthreader_agent" ); - QVERIFY( type.isValid() ); - job = new AgentInstanceCreateJob( type ); - QVERIFY( !job->exec() ); - } -}; - -QTEST_KDEMAIN( ResourceTest, NoGUI ) - -#include "resourcetest.moc" diff --git a/akonadi/tests/searchjobtest.cpp b/akonadi/tests/searchjobtest.cpp deleted file mode 100644 index dc0cffc00..000000000 --- a/akonadi/tests/searchjobtest.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "searchjobtest.h" -#include "searchjobtest.moc" - -#include -#include -#include -#include - -#include "collectionutils_p.h" - -#include - -QTEST_KDEMAIN( SearchJobTest, NoGUI ) - -using namespace Akonadi; - -void SearchJobTest::testCreateDeleteSearch() -{ - SearchCreateJob *create = new SearchCreateJob( "search123456", "Akonadi", this ); - QVERIFY( create->exec() ); - - CollectionFetchJob *list = new CollectionFetchJob( Collection( 1 ), CollectionFetchJob::Recursive, this ); - QVERIFY( list->exec() ); - Collection::List cols = list->collections(); - Collection col; - foreach ( const Collection &c, cols ) { - if ( c.name() == "search123456" ) - col = c; - } - QVERIFY( col.isValid() ); - QCOMPARE( col.parent(), 1LL ); - QVERIFY( CollectionUtils::isVirtual( col ) ); - - CollectionDeleteJob *delJob = new CollectionDeleteJob( col, this ); - QVERIFY( delJob->exec() ); -} diff --git a/akonadi/tests/searchjobtest.h b/akonadi/tests/searchjobtest.h deleted file mode 100644 index 40bb8f7be..000000000 --- a/akonadi/tests/searchjobtest.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_SEARCHJOBTEST_H -#define AKONADI_SEARCHJOBTEST_H - -#include - -class SearchJobTest : public QObject -{ - Q_OBJECT - private slots: - void testCreateDeleteSearch(); -}; - - -#endif diff --git a/akonadi/tests/subscriber.cpp b/akonadi/tests/subscriber.cpp deleted file mode 100644 index c2cc50d85..000000000 --- a/akonadi/tests/subscriber.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include - -#include -#include -#include - -int main( int argc, char** argv ) -{ - QApplication app( argc, argv ); - app.setQuitOnLastWindowClosed( false ); - KComponentData kcd( "akonadi" ); - Akonadi::SubscriptionDialog* dlg = new Akonadi::SubscriptionDialog(); - QObject::connect( dlg, SIGNAL(destroyed(QObject*)), &app, SLOT(quit()) ); - dlg->show(); - app.exec(); -} diff --git a/akonadi/tests/subscriptiontest.cpp b/akonadi/tests/subscriptiontest.cpp deleted file mode 100644 index 4cd2b3fa9..000000000 --- a/akonadi/tests/subscriptiontest.cpp +++ /dev/null @@ -1,87 +0,0 @@ -/* - Copyright (c) 2007 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include -#include -#include -#include - -#include - -#include - -using namespace Akonadi; - -class SubscriptionTest : public QObject -{ - Q_OBJECT - private slots: - void initTestCase() - { - Control::start(); - } - - void testSubscribe() - { - Collection::List l; - l << Collection( 5 ); - SubscriptionJob *sjob = new SubscriptionJob( this ); - sjob->unsubscribe( l ); - QVERIFY( sjob->exec() ); - - CollectionFetchJob *ljob = new CollectionFetchJob( Collection( 7 ), CollectionFetchJob::FirstLevel, this ); - QVERIFY( ljob->exec() ); - QCOMPARE( ljob->collections().count(), 1 ); - - ljob = new CollectionFetchJob( Collection( 7 ), CollectionFetchJob::FirstLevel, this ); - ljob->includeUnsubscribed(); - QVERIFY( ljob->exec() ); - QCOMPARE( ljob->collections().count(), 2 ); - - sjob = new SubscriptionJob( this ); - sjob->subscribe( l ); - QVERIFY( sjob->exec() ); - - ljob = new CollectionFetchJob( Collection( 7 ), CollectionFetchJob::FirstLevel, this ); - QVERIFY( ljob->exec() ); - QCOMPARE( ljob->collections().count(), 2 ); - } - - void testEmptySubscribe() - { - Collection::List l; - SubscriptionJob *sjob = new SubscriptionJob( this ); - QVERIFY( sjob->exec() ); - } - - void testInvalidSubscribe() - { - Collection::List l; - l << Collection( 1 ); - SubscriptionJob *sjob = new SubscriptionJob( this ); - sjob->subscribe( l ); - l << Collection( INT_MAX ); - sjob->unsubscribe( l ); - QVERIFY( !sjob->exec() ); - } -}; - -QTEST_KDEMAIN( SubscriptionTest, NoGUI ) - -#include "subscriptiontest.moc" diff --git a/akonadi/tests/testattribute.h b/akonadi/tests/testattribute.h deleted file mode 100644 index 3ca931048..000000000 --- a/akonadi/tests/testattribute.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - Copyright (c) 2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef TESTATTRIBUTE_H -#define TESTATTRIBUTE_H - -#include - -/* Attribute used for testing by various unit tests. */ -class TestAttribute : public Akonadi::Attribute -{ - public: - QByteArray type() const { return "EXTRA"; } - QByteArray serialized() const { return data; } - void deserialize( const QByteArray &ba ) { data = ba; } - TestAttribute* clone() const { TestAttribute* a = new TestAttribute; a->data = data; return a; } - QByteArray data; -}; - -#endif diff --git a/akonadi/tests/transactiontest.cpp b/akonadi/tests/transactiontest.cpp deleted file mode 100644 index 6514014b5..000000000 --- a/akonadi/tests/transactiontest.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* - Copyright (c) 2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "transactiontest.h" - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -using namespace Akonadi; - -QTEST_KDEMAIN( TransactionTest, NoGUI ) - -void TransactionTest::initTestCase() -{ - Control::start(); -} - -void TransactionTest::testTransaction() -{ - Collection basisCollection; - - CollectionFetchJob *listJob = new CollectionFetchJob( Collection::root(), CollectionFetchJob::Recursive ); - QVERIFY( listJob->exec() ); - Collection::List list = listJob->collections(); - foreach ( const Collection &col, list ) - if ( col.name() == "res3" ) - basisCollection = col; - - Collection testCollection; - testCollection.setParent( basisCollection ); - testCollection.setName( "transactionTest" ); - testCollection.setRemoteId( "transactionTestRemoteId" ); - CollectionCreateJob *job = new CollectionCreateJob( testCollection, Session::defaultSession() ); - - QVERIFY( job->exec() ); - - testCollection = job->collection(); - - TransactionBeginJob *beginTransaction1 = new TransactionBeginJob( Session::defaultSession() ); - QVERIFY( beginTransaction1->exec() ); - - TransactionBeginJob *beginTransaction2 = new TransactionBeginJob( Session::defaultSession() ); - QVERIFY( beginTransaction2->exec() ); - - TransactionCommitJob *commitTransaction2 = new TransactionCommitJob( Session::defaultSession() ); - QVERIFY( commitTransaction2->exec() ); - - TransactionCommitJob *commitTransaction1 = new TransactionCommitJob( Session::defaultSession() ); - QVERIFY( commitTransaction1->exec() ); - - TransactionCommitJob *commitTransactionX = new TransactionCommitJob( Session::defaultSession() ); - QVERIFY( commitTransactionX->exec() == false ); - - TransactionBeginJob *beginTransaction3 = new TransactionBeginJob( Session::defaultSession() ); - QVERIFY( beginTransaction3->exec() ); - - Item item; - item.setMimeType( "application/octet-stream" ); - item.setPayload( "body data" ); - ItemCreateJob *appendJob = new ItemCreateJob( item, testCollection, Session::defaultSession() ); - QVERIFY( appendJob->exec() ); - - TransactionRollbackJob *rollbackTransaction3 = new TransactionRollbackJob( Session::defaultSession() ); - QVERIFY( rollbackTransaction3->exec() ); - - ItemFetchJob *fetchJob = new ItemFetchJob( testCollection, Session::defaultSession() ); - QVERIFY( fetchJob->exec() ); - - QVERIFY( fetchJob->items().isEmpty() ); - - CollectionDeleteJob *deleteJob = new CollectionDeleteJob( testCollection, Session::defaultSession() ); - QVERIFY( deleteJob->exec() ); -} - -#include "transactiontest.moc" diff --git a/akonadi/tests/transactiontest.h b/akonadi/tests/transactiontest.h deleted file mode 100644 index 797923ea0..000000000 --- a/akonadi/tests/transactiontest.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - Copyright (c) 2008 Tobias Koenig - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef TRANSACTIONTEST_H -#define TRANSACTIONTEST_H - -#include - -class TransactionTest : public QObject -{ - Q_OBJECT - private Q_SLOTS: - void initTestCase(); - void testTransaction(); -}; - -#endif diff --git a/akonadi/transactionjobs.cpp b/akonadi/transactionjobs.cpp deleted file mode 100644 index 662ad0dba..000000000 --- a/akonadi/transactionjobs.cpp +++ /dev/null @@ -1,103 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "transactionjobs.h" - -#include "job_p.h" - -using namespace Akonadi; - -class Akonadi::TransactionBeginJobPrivate : public JobPrivate -{ - public: - TransactionBeginJobPrivate( TransactionBeginJob *parent ) - : JobPrivate( parent ) - { - } -}; - -class Akonadi::TransactionRollbackJobPrivate : public JobPrivate -{ - public: - TransactionRollbackJobPrivate( TransactionRollbackJob *parent ) - : JobPrivate( parent ) - { - } -}; - -class Akonadi::TransactionCommitJobPrivate : public JobPrivate -{ - public: - TransactionCommitJobPrivate( TransactionCommitJob *parent ) - : JobPrivate( parent ) - { - } -}; - - -TransactionBeginJob::TransactionBeginJob(QObject * parent) - : Job( new TransactionBeginJobPrivate( this ), parent ) -{ - Q_ASSERT( parent ); -} - -TransactionBeginJob::~TransactionBeginJob() -{ -} - -void TransactionBeginJob::doStart() -{ - d_ptr->writeData( d_ptr->newTag() + " BEGIN\n" ); -} - - - -TransactionRollbackJob::TransactionRollbackJob(QObject * parent) - : Job( new TransactionRollbackJobPrivate( this ), parent ) -{ - Q_ASSERT( parent ); -} - -TransactionRollbackJob::~TransactionRollbackJob() -{ -} - -void TransactionRollbackJob::doStart() -{ - d_ptr->writeData( d_ptr->newTag() + " ROLLBACK\n" ); -} - - - -TransactionCommitJob::TransactionCommitJob(QObject * parent) - : Job( new TransactionCommitJobPrivate( this ), parent ) -{ - Q_ASSERT( parent ); -} - -TransactionCommitJob::~TransactionCommitJob() -{ -} - -void TransactionCommitJob::doStart() -{ - d_ptr->writeData( d_ptr->newTag() + " COMMIT\n" ); -} - -#include "transactionjobs.moc" diff --git a/akonadi/transactionjobs.h b/akonadi/transactionjobs.h deleted file mode 100644 index eb757d172..000000000 --- a/akonadi/transactionjobs.h +++ /dev/null @@ -1,142 +0,0 @@ -/* - Copyright (c) 2006 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_TRANSACTIONJOBS_H -#define AKONADI_TRANSACTIONJOBS_H - -#include "akonadi_export.h" - -#include - -namespace Akonadi { - -class TransactionBeginJobPrivate; -class TransactionRollbackJobPrivate; -class TransactionCommitJobPrivate; - -/** - * @short Job that begins a session-global transaction. - * - * Sometimes you want to execute a sequence of commands in - * an atomic way, so that either all commands or none shall - * be executed. The TransactionBeginJob, TransactionCommitJob and - * TransactionRollbackJob provide these functionality for the - * Akonadi Job classes. - * - * @note This will only have an effect when used as a subjob or with a Session. - * - * @author Volker Krause - */ -class AKONADI_EXPORT TransactionBeginJob : public Job -{ - Q_OBJECT - - public: - /** - * Creates a new transaction begin job. - * - * @param parent The parent job or Session, must not be 0. - */ - explicit TransactionBeginJob( QObject *parent ); - - /** - * Destroys the transaction begin job. - */ - ~TransactionBeginJob(); - - protected: - virtual void doStart(); - - private: - Q_DECLARE_PRIVATE( TransactionBeginJob ) -}; - - -/** - * @short Job that aborts a session-global transaction. - * - * If a job inside a TransactionBeginJob has been failed, - * the TransactionRollbackJob can be used to rollback all changes done by these - * jobs. - * - * @note This will only have an effect when used as a subjob or with a Session. - * - * @author Volker Krause - */ -class AKONADI_EXPORT TransactionRollbackJob : public Job -{ - Q_OBJECT - - public: - /** - * Creates a new transaction rollback job. - * The parent must be the same parent as for the TransactionBeginJob. - * - * @param parent The parent job or Session, must not be 0. - */ - explicit TransactionRollbackJob( QObject *parent ); - - /** - * Destroys the transaction rollback job. - */ - ~TransactionRollbackJob(); - - protected: - virtual void doStart(); - - private: - Q_DECLARE_PRIVATE( TransactionRollbackJob ) -}; - - -/** - * @short Job that commits a session-global transaction. - * - * This job commits all changes of this transaction. - * - * @author Volker Krause - */ -class AKONADI_EXPORT TransactionCommitJob : public Job -{ - Q_OBJECT - - public: - /** - * Creates a new transaction commit job. - * The parent must be the same parent as for the TransactionBeginJob. - * - * @param parent The parent job or Session, must not be 0. - */ - explicit TransactionCommitJob( QObject *parent ); - - /** - * Destroys the transaction commit job. - */ - ~TransactionCommitJob(); - - protected: - virtual void doStart(); - - private: - Q_DECLARE_PRIVATE( TransactionCommitJob ) -}; - -} - -#endif diff --git a/akonadi/transactionsequence.cpp b/akonadi/transactionsequence.cpp deleted file mode 100644 index 4a01a3781..000000000 --- a/akonadi/transactionsequence.cpp +++ /dev/null @@ -1,145 +0,0 @@ -/* - Copyright (c) 2006-2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#include "transactionsequence.h" -#include "transactionjobs.h" - -#include "job_p.h" - -using namespace Akonadi; - -class Akonadi::TransactionSequencePrivate : public JobPrivate -{ - public: - TransactionSequencePrivate( TransactionSequence *parent ) - : JobPrivate( parent ), - mState( Idle ) - { - } - - enum TransactionState - { - Idle, - Running, - WaitingForSubjobs, - RollingBack, - Committing - }; - - Q_DECLARE_PUBLIC( TransactionSequence ) - - TransactionState mState; - - void commitResult( KJob *job ) - { - Q_Q( TransactionSequence ); - - if ( job->error() ) { - q->setError( job->error() ); - q->setErrorText( job->errorText() ); - } - q->emitResult(); - } - - void rollbackResult( KJob *job ) - { - Q_Q( TransactionSequence ); - - Q_UNUSED( job ); - q->emitResult(); - } -}; - -TransactionSequence::TransactionSequence( QObject * parent ) - : Job( new TransactionSequencePrivate( this ), parent ) -{ -} - -TransactionSequence::~TransactionSequence() -{ -} - -bool TransactionSequence::addSubjob(KJob * job) -{ - Q_D( TransactionSequence ); - - if ( d->mState == TransactionSequencePrivate::Idle ) { - d->mState = TransactionSequencePrivate::Running; - new TransactionBeginJob( this ); - } - return Job::addSubjob( job ); -} - -void TransactionSequence::slotResult(KJob * job) -{ - Q_D( TransactionSequence ); - - if ( !job->error() ) { - Job::slotResult( job ); - if ( subjobs().isEmpty() && d->mState == TransactionSequencePrivate::WaitingForSubjobs ) { - d->mState = TransactionSequencePrivate::Committing; - TransactionCommitJob *job = new TransactionCommitJob( this ); - connect( job, SIGNAL(result(KJob*)), SLOT(commitResult(KJob*)) ); - } - } else { - setError( job->error() ); - setErrorText( job->errorText() ); - removeSubjob( job ); - clearSubjobs(); - if ( d->mState == TransactionSequencePrivate::Running || d->mState == TransactionSequencePrivate::WaitingForSubjobs ) { - d->mState = TransactionSequencePrivate::RollingBack; - TransactionRollbackJob *job = new TransactionRollbackJob( this ); - connect( job, SIGNAL(result(KJob*)), SLOT(rollbackResult(KJob*)) ); - } - } -} - -void TransactionSequence::commit() -{ - Q_D( TransactionSequence ); - - if ( d->mState == TransactionSequencePrivate::Running ) - d->mState = TransactionSequencePrivate::WaitingForSubjobs; - else - return; - - if ( subjobs().isEmpty() ) { - if ( !error() ) { - d->mState = TransactionSequencePrivate::Committing; - TransactionCommitJob *job = new TransactionCommitJob( this ); - connect( job, SIGNAL(result(KJob*)), SLOT(commitResult(KJob*)) ); - } else { - d->mState = TransactionSequencePrivate::RollingBack; - TransactionRollbackJob *job = new TransactionRollbackJob( this ); - connect( job, SIGNAL(result(KJob*)), SLOT(rollbackResult(KJob*)) ); - } - } -} - -void TransactionSequence::doStart() -{ - Q_D( TransactionSequence ); - - if ( d->mState == TransactionSequencePrivate::Idle ) - emitResult(); - else - commit(); -} - -#include "transactionsequence.moc" diff --git a/akonadi/transactionsequence.h b/akonadi/transactionsequence.h deleted file mode 100644 index 5559742c1..000000000 --- a/akonadi/transactionsequence.h +++ /dev/null @@ -1,82 +0,0 @@ -/* - Copyright (c) 2006-2008 Volker Krause - - This library is free software; you can redistribute it and/or modify it - under the terms of the GNU Library General Public License as published by - the Free Software Foundation; either version 2 of the License, or (at your - option) any later version. - - This library is distributed in the hope that it will be useful, but WITHOUT - ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public - License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to the - Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA - 02110-1301, USA. -*/ - -#ifndef AKONADI_TRANSACTIONSEQUENCE_H -#define AKONADI_TRANSACTIONSEQUENCE_H - -#include "akonadi_export.h" - -#include - -namespace Akonadi { - -class TransactionSequencePrivate; - -/** - * @short Base class for jobs that need to run a sequence of sub-jobs in a transaction. - * - * As soon as the first subjob is added, the transaction is started. - * As soon as the last subjob has successfully finished, the transaction is committed. - * If any subjob fails, the transaction is rolled back. - * - * Alternatively, a TransactionSequence object can be used as a parent object - * for a set of jobs to achieve the same behaviour without subclassing. - * - * @author Volker Krause - */ -class AKONADI_EXPORT TransactionSequence : public Job -{ - Q_OBJECT - public: - /** - * Creates a new transaction sequence. - * - * @param parent The parent object. - */ - explicit TransactionSequence( QObject *parent = 0 ); - - /** - * Destroys the transaction sequence. - */ - ~TransactionSequence(); - - /** - * Commits the transaction as soon as all pending sub-jobs finished successfully. - */ - void commit(); - - protected: - bool addSubjob( KJob* job ); - void doStart(); - - protected Q_SLOTS: - void slotResult( KJob *job ); - - private: - Q_DECLARE_PRIVATE( TransactionSequence ) - - //@cond PRIVATE - Q_PRIVATE_SLOT( d_func(), void commitResult(KJob*) ) - Q_PRIVATE_SLOT( d_func(), void rollbackResult(KJob*) ) - //@endcond -}; - -} - -#endif